Currently I have the following Play project structure:
PlayApp
modules
common
sub_project_two
PlayApp is marked as a module, dependent on common.
modules is just a directory.
common is a sub project(also a play app).
sub_project_two is a sub project(also a play app), which is dependent on common.
Unfortunately I cannot just right click on "modules" and create new module(play app) and move on. Currently, I literally have to right click PlayApp and create the new module then move it to "modules", and it is running into dependency issues in Intellij and failing to import the classes inside "common".
What is the correct way of creating subprojects inside Intellij?
There is no any special way to create subprojects in Intellij. Subprojects are defined in sbt build file. Intellij will discover these projects and configure them as long as you have Scala plugin. I would imagine a following project structure in your build file:
lazy val PlayApp = Project("playApp", file(".")).aggregate(common, subProjectTwo)
lazy val common = Project("common", file("modules/common"))
lazy val subProjectTwo = Project("subProjectTwo", file("modules/sub_project_two"))
For more details visit: http://www.scala-sbt.org/0.13.5/docs/Getting-Started/Multi-Project.html
Related
Pretty simple; just created a Compose Multiplatform project from the wizard.
Went ahead and created the Theme; but I wanted to use the same font so I put poppins.ttf inside commonMain/resources/font/.
Then I declared the following in commonMain module:
expect val projectFontFamily: FontFamily
On the commonDesktop module I used:
actual val projectFontFamily: FontFamily = FontFamily(
Font("font/poppins.ttf")
)
Great, that worked. Now on commonAndroid:
actual val projectFontFamily: FontFamily = FontFamily(
Font(R.font.poppins)
)
For some reason the R class is not properly being generated and I cannot use R.font.poppins.
If I rename "resources" to "res" and shove the font into res/font/ then it works. (But I just duplicated the font file).
How do I get around doing this?
It turns out it's rather a gradle issue and some inexperience with KMM.
Kotlin multiplatform projects by default (regardless of the platform) provide their resources in a folder called resources inside each module.
Problem is that the default folder for Android needs to be called res
So you can apply a fix either way:
Change resources folders to res and modify gradle accordingly or indicate in the Android project that the resource folder is not res but resources.
We ended up doing the latter in our project
// build.gradle.kts
android {
...
sourceSets["main"].res.srcDirs(
"src/commonMain/resources",
"src/androidMain/resources"
)
...
}
I found this tutorial from JetBrains: https://www.jetbrains.com/help/idea/create-your-first-kotlin-app.html?section=Gradle%20Kotlin
It is dated August 19th, 2020.
I am using the same IntelliJ IDEA version as in their documentation: 2020.2.
However, my project creation wizard looks quite different from theirs.
They provide this screenshot:
But for me, it looks like this:
and when I click on Next:
I don't see where I can choose the Console Application template, or Gradle.
I found a second tutorial - https://kotlinlang.org/docs/tutorials/jvm-get-started.html , which shows yet a third variation of the New Project wizard:
Are the tutorials out of date? Am I doing anything wrong? How do I create a Kotlin project, based on a console application template, with Gradle?
The wizard you have seems to be obsolete now. There was a brand-new one, released as a part of Kotlin 1.4 recently(see here). Most probably, the problem is caused by the Kotlin IDE plugin being outdated or something. Please try to delete in and re-install using the Preferences -> Plugins menu. Comment here with the results, please. I'd like to know if this would help.
Indeed it's quite weird, I've never seen the dialog to look like yours (mine looks like the one in the tutorials). However, choosing the template doesn't do anything special - it simply creates the main file, which you can do so yourself.
So create a new project with the "JVM/IDEA" option. If it already opens up a main.kt file, you don't need to do anything else. If it didn't, look in the src folder - you should see a folder named main with a folder named kotlin (with a blue icon instead of grey) inside - here's where you wanna create your main file (right click -> new kotlin file/class -> main.kt and make it a file, not a class). Finally, put this in the file:
fun main(args: Array<String>) {
println("Hello world!")
}
Note: if you don't have a kotlin folder, create the file in the folder with the blue icon (might even be src). Also, if this doesn't use Gradle (for some reason), create a Gradle project instead, and at the "Additional libraries and frameworks" option, uncheck Java and check Kotlin, then continue with creating main.kt if it isn't created.
You may create a Kotlin + gradle project from the terminal:
$mkdir myProject; cd myProject; gradle init
follow the tutorial.
And then start the Intellij & open the dir
You're good to go
Same process like this
The same happened to me but I figured out how to fix it:
Just disable Material Theme UI.
I combine Xtext and Xtend. In project, where I write code for my DSL, Xtext work but XTend not generate file in src-gen (this is sources root on: <project-root>/src-gen/).
I have this code in function doGenerate
override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
fsa.generateFile("a.txt",'a')
}
Src-gen is always empty. In eclipse this work. How can I generate file in IntelliJ IDEA or how can I fix this problem. I run in gradle.
I run gradle task runIdea. I create Java project without any SDK.
When project is created, I add "file.mydsl" in src folder. Then I need change facet settings. I open project structure dialog (Ctrl+Shift+Alt+S), in the left-hand panel, click Facets, choose + icon and add DSL facet. Then apply and code is work. In src-gen create a file "a.txt".
I am wondering how to configure the following project layout in IntelliJ:
An Android application
A server back end feeding data to this application
Bean classes that are shared between back end and Android application
Initially, I wanted to create three modules on an equal hierarchy level. However, this does not seem to be possible with IntelliJ. I can only add new modules inside of the first module. I wonder if this is the way I am supposed to do it? Or is there a better way to do configure this project layout with IntelliJ? Do these hierarchies only represent folders?
I feel like I should make (3) a library module and add dependencies to (1) and (2). Since a module is defined as a discrete unit of functionality which you can compile, run, test and debug independently I feel like this is the right approach.
This is my first multi-module project in IntelliJ. Any explanation is appreciated!
When creating a new project you can use the Empty Project option on the first wizard step. When the project is created, add 3 modules in different folders under the Project Structure settings.
If you want to add them on a already initialized project, the trick from #CrazyCoder works, but you must not choose Empty Project, but instead Empty Module (in the Project Structure -> Modules dialog).
Then, choose the existing project.
Lastly, on the right side, the content root might be wrong. Set it to the root of your module.
Make sure the submodules are not on root level on the Project Structure -> Modules page. If they are, remove all expect the root module, delete the content root on the right, and add it again.
I'm not able to use a module which I created by myself. I do everything like the following description:
http://java.dzone.com/articles/writing-modules-play-2-get
But there are little changes which shouldn't have any influence of the functionality: I don't change the project-struktur and i create separates projects in different folders. I think I should describe my steps for using and creating my own module and perhaps anyone see my mistake:
I create one project with play new testapp (workspace/testapp). Then i create an other projekt with play new testmodul (workspace/testmodul). Then i go to the testmodul and delete the route-file and the content of the application.conf. Then i create a class called "Tester" with the method test. (a simple system.out) After that i exceute "clean", "compile" and "publish-local" in the testmodul-folder.
In my understanding the modul ist published in the local repository of play and every application which want to use this module will have access to the local repository version of the module.
Now I go to the testapp and create the dependencies in the Build.scala. After that i go to the default-Application.class and add the line "Tester.test();". Then I excecute the dependencies command and try to compile.
After that i get the error, "can't find symbol". It seemed to be that the testapp don't know the Tester.class and that means that the testapp don't know the module.
But I don't know why.
Has anybody an idea?
Edit:
Perhaps I should display my dependencie config of the testapp:
val appDependencies = Seq(
// Add your project dependencies here,
javaCore
,javaJdbc
,javaEbean
,"testmodul" % "testmodul_2.10" % "1.0-SNAPSHOT"
)
val main = play.Project(appName, appVersion, appDependencies).settings(
// Add your own project settings here
resolvers += "Local Play Repository" at "file://C:/play-2.1.0/repository/local"
)
I'm not sure why the solution above wasn't right, but i found a solution. I found out that in the documentation of the playframework "modules" called "subprojects" there I found how to include modules. (http://www.playframework.com/documentation/2.1.0/SBTSubProjects)
But I think the other way of "global" modules should also be possible.
Change this line
resolvers += "Local Play Repository" at "file://C:/play-2.1.0/repository/local"
To
resolvers += "Local Play Repository" at "file://play-2.1.0/repository/local"
Just remove the C:/ .It worked for me. Check this http://www.objectify.be/wordpress/?p=363.