As I was not able to resolve the issue I have with kotlin
, I decided to return to groovy
in order to implement the plugin.
However I ran into the issue. I have such project structure.
In order not to rewrite all classes I decided to reuse classes implemented in kotlin
.
However my classes FileProcessingCoreGroovy
& DownloadCoreGroovy
are unable to resolve class ProcessStream
and UnpackStream
.
I thought they should be able freely use each other but I guess I was wrong. What is the problem?
The classes itself are imported just fine by IDE (not marked in red color and so on)
The console output looks like this (I use another class where I import PluginUtils
from kotlin
classes)
:clean
:compileKotlin (...multiple deprecated messages...)
:compileJava UP-TO-DATE
:compileGroovy
startup failed:
D:\groovy_apps\MISC\gradle-app-environment-plugin\src\main\groovy\com.lapots.gradle.plugins.appenv\ApplicationEnvironmentGroovyPlugin.g
roovy: 4: unable to resolve class com.lapots.gradle.plugins.appenv.core.PluginUtils
@ line 4, column 1.
import com.lapots.gradle.plugins.appenv.core.PluginUtils
^
Looks like it is not so simple.
See https://discuss.gradle.org/t/kotlin-groovy-and-java-compilation/14903/2
Using suggestions from there, I added
compileGroovy {
dependsOn tasks.getByPath('compileKotlin')
classpath += files(compileKotlin.destinationDir)
}
And it worked.
vuk's answer eventually solved the problem for me.
However, it did not work immediately. Some of my Groovy Spock tests depended on a test utility in Kotlin, and I spent a lot of time figuring out what is wrong. It turned out that I did not move my Kotlin file out of the src/test/groovy
folder, thus it was not compiled at the right time.
Make sure that every file is in the correct subfolder according to the language.
For example:
src
+---- main
| +---- kotlin
| +---- ...
+---- test
+---- groovy
| +---- ...
+---- kotlin
+---- ...
For tests, this Gradle code will compile Kotlin before Groovy:
compileTestGroovy {
dependsOn tasks.getByPath('compileTestKotlin')
classpath += files(compileTestKotlin.destinationDir)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With