How to import multi-module project in IntelliJ IDEA? - intellij-idea

I'm used to Spring and Maven projects where I set up a multi-module project in Maven with projects like:
app-web
app-models
app-services
app-common
I'm now getting into using Play Framework 2 (Scala) and sbt.
Is there a similar concept with Play and sbt that I could group all of these projects into a single IntelliJ IDEA solution and sbt?

IntelliJ IDEA 13 (the latest version is 13.1.3) comes with the built-in SBT support, and the Ultimate edition adds Play support.
A multi-module sbt project can be imported to IDEA and is fully supported out of the box however it's Play-based or not (they're sbt projects after all).
You should try it out yourself with the following very simplistic build file build.sbt (or just generate a Play project with play new or better now activator new [your-project-name] play-scala):
lazy val a, b, c = project
and the following project/build.properties:
sbt.version=0.13.5
Nothing but these two above files are needed to get you started with sbt/activator.
In IDEA, open the project using File > Open... and select build.sbt.
Click OK to see another window where you specify additional configuration options for the project. Then the modules show up.

You probably wouldn't be able to group them into one single project in idea but you could have multiple projects for sure:
in your project/Build.scala:
{
val baseDependencies = Seq(
"org1" % "dep" % "latest.integration",
"org2" % "dep2" % "version"
)
val modelDependencies = baseDependencies ++ Seq("org3" % "dep3" % "version")
val appWeb = play.Project("app-web", "1.0", baseDependencies)
val appModels = play.Project("app-models", "1.0", modelDependencies, path = file("modules/models"))
val app = play.Project("app", "1.0", Nil).aggregate(appWeb, appModels)
}
In this case, you'll have a regular app called "app-web", a module appModels under modules/models without the project directory and regular confs like application.conf, and an aggregated app called "app".
When you start the play console you could switch to certain projects by typing "project (name)". For example you could type "project app-web" and then "idea" to generate the app-web project solution for idea. You can also switch to project "app" where all commands entered under it will be applied to all sub-projects.
For more, check the documentation here: http://www.playframework.com/documentation/2.2.x/SBTSubProjects

Related

How to fix third party dll include not being staged correctly by Unreal Build Tool?

I am using a pre-built C++ library in my Unreal project using a dynamic library file (let's say it's called MyPluginLib.dll). The library is contained in a plugin, let’s call it MyPlugin.
Building, packaging, playing in editor works fine. However, a packaged build doesn’t start, giving the following error: Code execution cannot proceed, MyPluginLib.dll was not found.
The packaging process places MyPluginLib.dll file in MyGame\Plugins\MyPlugin\Binaries. However, the execution process is seemingly looking for it in MyGame\Binaries – moving the library there manually solves this issue.
Why is the OS unable to find the dll in the first folder? Is there something wrong in the build.cs, or my folder structure?
The folder structure of the plugin folder is as follows:
Includes in Plugins\MyPlugin\Source\ThirdParty\MyPluginLib\
Binaries in Plugins\MyPlugin\Binaries\(PLATFORM)\
The plugin’s Build.cs looks like this:
public class MyPlugin : ModuleRules
{
public MyPlugin(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
string PluginRoot = Path.GetFullPath(Path.Combine(ModuleDirectory, "..", ".."));
string PlatformString = Target.Platform.ToString();
string LibraryDirectory = Path.Combine(PluginRoot, "Binaries", PlatformString);
PublicIncludePaths.Add(Path.Combine(PluginRoot, "Source", "ThirdParty", "MyPluginLib"));
if ((Target.Platform == UnrealTargetPlatform.Win64))
{
PublicAdditionalLibraries.Add(Path.Combine(LibraryDirectory, "MyPluginLib.lib"));
RuntimeDependencies.Add(Path.Combine(LibraryDirectory, "MyPluginLib.dll"), StagedFileType.NonUFS);
}
else if (Target.Platform == UnrealTargetPlatform.Linux)
{
// linux binaries...
}
}
Would appreciate any help.
Check your packaged games files, unreal loves to not include certain thing in packaged builds regarding plugins.

Intellij running multiple kotlin files inside project, instead the one selected

Learning Kotlin and IntelliJ,
Before yesterday if I wanted to run one single .kt file, it was all good. Many ways to do it.
I was doing various exercises, all in the same file exercises.kt. After finishing a code, I would just transform it into a comment and start the next one in the same file.
After many exercises, I decided to create a .kt file for each one. But, now, when I run a single file for one exercise Intellij is running ALL files inside the project, instead of just the one I selected.
EDIT: Every .kt file got its own main function, some with a class. To run a single file I used different methods. Clicking the play button at the left of the main function, or clicking the play button at the top bar with the current file selected and clicling with the right button on top of the file in the project list and selecting "Run filekt" (Same as Ctrt + shift + F10). Like I said before the change explained it was all good.
Here it is my run configuration:
Content of one of my files that was single running before I changed
fun main() {
val amanda = Person("Amanda", 33, "play tennis", null)
val atiqah = Person("Atiqah", 28, "climb", amanda)
amanda.showProfile()
atiqah.showProfile()
}
class Person(val name: String, val age: Int, val hobby: String?, val referrer: Person?) {
fun showProfile() {
when {
referrer == null -> println("""Name: ${name}
Age: ${age}
Likes to ${hobby}. Doesn't have a referrer."""")
else -> println("""Name: ${name}
Age: ${age}
Likes to ${hobby}. Has a referrer named ${referrer.name}, who likes to ${referrer.hobby}""")
}
}
}
When Intellij run all the files, this is showing in the project errors. This is new as well. If I try to run the SongCatalog files on Kotlin Playground it's all good.(The Special Auction is in progress)
For the rest of the files, here's the repository: Google Learning Repo
IntelliJ does not run all the files. It compiles all the files, but only runs the file that you specified in the run configuration.
However, since two of your files, SongCatalog.kt and SongCatalog2.kt, both declare a SongCatalog class, there is a compiler error. The same class cannot be declared twice, after all. Even if you are just trying to run some other file, all the files in your project has to be compiled.
Using Packages
I recommend just putting each exercise that you are doing in its package. This way the two SongCatalogs are distinct. For example, at the start of SongCatalog.kt, you can write:
package exercise4_1
and at the start of SongCatalog2.kt, you can write:
package exercise4_2
Put each file into a folder with the same name as the package. Do this for all the other files containing your exercises so that it's organised.
Make sure that IntelliJ don't automatically insert imports, importing things from other exercises, causing conflicts again.
Then in your run configuration, write add the package name as a prefix for the main class. For example, to run SongCatalog.kt, you'd write exercise4_1.SongCatalogKt.
Using Modules
There is also another rather overkill method of having IntelliJ only compile a part of your project's files. You can put each of your exercises' files into a different module.
To add a module, go to File -> New -> Module. Then you can give that module a name and add new .kt files to the /src folder of that module.
Configure your run configuration the same way as before, except choose the module that you want to run in the "use class path of module" dropdown.

How to build a gradle project without a specific subfolder?

I have a Kotlin project in Gradle with 3 main folders: myorg.folder1, myorg.folder2, and myorg.folder3. Due to project constraints I cannot change this structure. As part of the project, I would like to have two different jar distributions: One containing all 3 folders, and one that only contains folder1 and folder2. The project has been set up so that these folders can operate independently of folder3 without errors. How can I do this?
In order to do this, (following broot's advice, thanks), I was able to find that I needed to use a sourceSet to make this work.
sourceSets {
noFolder3
kotlin {
exclude "myorg/folder3/**"
}
}
}
Then, I can build with all 3 folders using build, and without folder3 using build noFolder3.
One extra note is that since I was using Intellij IDEA, all of my code was stored in the directory src/main/kotlin, so I also added the following line inside the kotlin {} block:
srcDirs += "src/main/kotlin"

idea `org.jetbrains.plugins.go` not found

I had this problem when I was developing the GoLand plug-in and install plugin from build jar Plugin Gorm Generator depends on unknown plugin com.intellij.velocity
<depends>org.jetbrains.plugins.go</depends>
build.gradle:
intellij {
version '2020.2.1'
sandboxDirectory = "${rootProject.rootDir}/idea-sandbox"
type 'IU'
plugins = ['java', 'DatabaseTools', 'Velocity']
updateSinceUntilBuild false
setPlugins("org.jetbrains.plugins.go:202.7319.5")
}
i'm not find
You're setting the plugins list twice - by assigning an array to the plugins property and calling setPlugins method. That makes your first array simply overwritten by the Go dependency.
Try with the first approach only and simply append the Go entry at the end of your array.

How to disable default gradle buildType suffix (-release, -debug)

I migrated a 3rd-party tool's gradle.build configs, so it uses android gradle plugin 3.5.3 and gradle 5.4.1.
The build goes all smoothly, but when I'm trying to make an .aab archive, things got broken because the toolchain expects the output .aab file to be named MyApplicationId.aab, but the new gradle defaults to output MyApplicationId-release.aab, with the buildType suffix which wasn't there.
I tried to search for a solution, but documentations about product flavors are mostly about adding suffix. How do I prevent the default "-release" suffix to be added? There wasn't any product flavor blocks in the toolchain's gradle config files.
I realzed that I have to create custom tasks after reading other questions and answers:
How to change the generated filename for App Bundles with Gradle?
Renaming applicationVariants.outputs' outputFileName does not work because those are for .apks.
I'm using Gradle 5.4.1 so my Copy task syntax reference is here.
I don't quite understand where the "app.aab" name string came from, so I defined my own aabFile name string to match my toolchain's output.
I don't care about the source file so it's not deleted by another delete task.
Also my toolchain seems to be removing unknown variables surrounded by "${}" so I had to work around ${buildDir} and ${flavor} by omitting the brackets and using concatenation for proper delimiting.
tasks.whenTaskAdded { task ->
if (task.name.startsWith("bundle")) { // e.g: buildRelease
def renameTaskName = "rename${task.name.capitalize()}Aab" // renameBundleReleaseAab
def flavorSuffix = task.name.substring("bundle".length()).uncapitalize() // "release"
tasks.create(renameTaskName, Copy) {
def path = "$buildDir/outputs/bundle/" + "$flavorSuffix/"
def aabFile = "${android.defaultConfig.applicationId}-" + "$flavorSuffix" + ".aab"
from(path) {
include aabFile
rename aabFile, "${android.defaultConfig.applicationId}.aab"
}
into path
}
task.finalizedBy(renameTaskName)
}
}
As the original answer said: This will add more tasks than necessary, but those tasks will be skipped since they don't match any folder.
e.g.
Task :app:renameBundleReleaseResourcesAab NO-SOURCE