So I have multi-project based Grandle build where I use Kotlin as primary language. Say default project is named as app
which has both src/main/kotlin
and src/main/resources
directories. The werid thing is I can't access resources from the code even if Gradle sets it to the correct one. I was comparing it to the single-project build (the one that has src
as main source directory) and when I run:
javaClass.getResource("./")
Both projects point to the same directory placed at build/classes/kotlin/main/
. But when I run:
javaClass.getResource("test.txt")
Single-project points to build/resources/test.txt
(which is as expected) but getting null
in app
of multi-project build. Of course file exists in both places
Did I miss some configuration in global build.gradle
or project's build.gradle
or something else?
Project structure and some important files parts:
+ app
| + src
| | + main
| | | + kotlin
| | | | - Main.kt
| | | + resources
| | | | - test.txt
| - build.gradle
- build.gradle
- settings.gradle
settings.gradle
include 'app'
build.gradle
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.72'
}
version '0.0.1'
subprojects {
apply plugin: 'java'
apply plugin: 'org.jetbrains.kotlin.jvm''
repositories {
mavenCentral()
jcenter()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib"
compile "org.reactfx:reactfx:1.4.1"
}
}
app/build.gradle
plugins {
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.9'
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-reflect:1.3.72"
testCompile group: 'junit', name: 'junit', version: '4.12'
}
javafx {
version = "11"
modules = ['javafx.controls', 'javafx.graphics', 'javafx.fxml']
}
mainClassName = 'MainApp.MainApp'
MainApp.kt
class MainApp {
companion object {
@JvmStatic
fun main(args: Array<String>) {
javaClass.getResource("test.txt") // this gives null
}
}
}