Skip to content

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

Description

@Marcono1234

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions