groovy is unable to resolve kotlin classes

2019-06-19 01:47发布

问题:

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
   ^                           

回答1:

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.



回答2:

I had the same problem. It has something to do with Kotlin companion objects. I moved static functions from companion object to package level and it started to work.



标签: groovy kotlin