Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails for Kotlin project due to circular dependency between tasks #14

Open
Marcono1234 opened this issue May 27, 2022 · 2 comments
Open

Comments

@Marcono1234
Copy link
Contributor

Marcono1234 commented May 27, 2022

Version

Plugin: 1.0.0-rc3
Gradle: 7.4.2

Description

Trying to use this plugin with a Kotlin JVM project fails due to a circular dependency between tasks. Gradle output:

FAILURE: Build failed with an exception.

* What went wrong:
Circular dependency between the following tasks:
:app:addDependenciesModuleInfo
+--- :app:generateModuleInfo
|    \--- :app:jar
|         +--- :app:classes
|         |    \--- :app:compileJava
|         |         \--- :app:addDependenciesModuleInfo (*)
|         \--- :app:inspectClassesForKotlinIC
|              \--- :app:classes (*)
\--- :app:jar (*)

(*) - details omitted (listed previously)

I also noticed some other issues when using moduleInfoSource; maybe it would be good to add some integration tests for Kotlin projects.

Thanks a lot nonetheless for providing this Gradle plugin and the corresponding Maven plugin. Their functionality is really great!

Reproduction steps

You can skip the steps for creating the project below and instead use https://github.com/Marcono1234/moditect-kotlin-test

  1. Create a sample Kotlin JVM project (e.g. by using gradle init)
  2. Use the following build.gradle.kts file
    plugins {
        kotlin("jvm") version "1.6.21"
        id("org.moditect.gradleplugin") version "1.0.0-rc3"
    }
    
    repositories {
        mavenCentral()
    }
    
    dependencies {
        implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
    }
    
    tasks.addMainModuleInfo {
        version = project.version
        jvmVersion.set("9")
        overwriteExistingFiles.set(true)
        module {
            moduleInfoFile = File("$projectDir/src/main/java-9/module-info.java")
        }
    }
  3. Run ./gradlew clean build
    ❌ It fails

Workaround

Add the following to the build.gradle.kts file:

project.afterEvaluate {
    val compileJavaTask = tasks.compileJava.get()
    compileJavaTask.setDependsOn(compileJavaTask.dependsOn - tasks.addDependenciesModuleInfo.get())
}

(Based on this related StackOverflow answer)

With that ./gradlew clean build succeeds and the generated JAR is properly configured as Multi-Release JAR and contains the compiled module-info.class.

@siordache
Copy link
Member

Thanks for reporting and analyzing the problem. Unfortunately, I don't have much time for the moditect-gradle-plugin these days, so it would be great if you could send a PR for this issue.

@Marcono1234
Copy link
Contributor Author

Sadly, I am neither familiar with Gradle plugin development nor with Groovy. I might give it a try in case this issue has an "easy" solution, but I am afraid this issue is caused by the following code (have not verified it yet) and there is probably a reason for this specific configuration:

compileJavaTask.taskDependencies.getDependencies(compileJavaTask).each { Task depTask ->
def depJarTask = depTask.project.tasks.findByName(JavaPlugin.JAR_TASK_NAME)
[addMainModuleInfoTask, addDependenciesModuleInfoTask, generateModuleInfoTask, createRuntimeImageTask].each {
it.dependsOn(depJarTask)
}
}
addDependenciesModuleInfoTask.dependsOn(generateModuleInfoTask)
compileJavaTask.dependsOn(addDependenciesModuleInfoTask)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants