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

When artifactId is different from project name, then in the generated POM there is a reference to itself, with testFixtures #885

Open
OlivierHartmann opened this issue Dec 18, 2024 · 2 comments

Comments

@OlivierHartmann
Copy link

OlivierHartmann commented Dec 18, 2024

Hi,
I hurt my head while migrating from groovy to kotlin, my project with submodules. But I found that the problem is here even with a simple project.
The problem is in gradle 7.5 and 8.10 with the testFixtures plugin.

Here is my build.gradle.kts

val gitlabMavenUrl: String by project
val gitlabMavenToken: String by project

group = "com.test"
extra["xmlunit2.version"] = "2.10.0" // Spring boot depends on 2.9.0 -> CVE-2024-31573

plugins {
    idea
    java

    kotlin("jvm") version libs.versions.kotlin
    kotlin("kapt") version libs.versions.kotlin

    id("java-library")
    id("maven-publish")
    id("java-test-fixtures")
}

kotlin {
    jvmToolchain(21)
}

dependencies {
    // Testing : Junit
    testImplementation(platform("org.junit:junit-bom:5.11.2"))
    testImplementation("org.junit.jupiter:junit-jupiter-api")
    testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
    testImplementation("org.junit.jupiter:junit-jupiter-params")
    testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
}

tasks.withType<Test> {
    useJUnitPlatform()
}

tasks.jar {
    from(sourceSets.main.get().allSource)
    from(sourceSets.testFixtures.get().allSource)
}

java {
    withJavadocJar()
    withSourcesJar()
}

tasks.javadoc {
    if (JavaVersion.current().isJava9Compatible) {
        (options as StandardJavadocDocletOptions).addBooleanOption("html5", true)
    }
}

publishing {
    repositories {
        maven {
            url = uri(gitlabMavenUrl)
            credentials(HttpHeaderCredentials::class) {
                name = "Deploy-Token"
                value = gitlabMavenToken
            }
            authentication {
                create("header", HttpHeaderAuthentication::class)
            }
        }
    }

    publications {
        create<MavenPublication>("libTest") {
            from(components["java"])
            artifactId = "lib-test"
        }
    }
}

sourceSets {
    main {
        java {
            srcDir("${layout.buildDirectory}/generated/source/kapt/main")
        }
    }
}

and my settings.grade.kts

rootProject.name = "lib-test"

pluginManagement {
    repositories {
        gradlePluginPortal()
        mavenCentral()
        maven {
            url = uri("https://plugins.gradle.org/m2/")
        }
    }
}

dependencyResolutionManagement {
    repositories {
        mavenCentral()
        maven { url = uri("https://maven.springframework.org/milestone/") }
    }
}

The main part here is this, where you can notice that the artifactId is the same as the project name :

rootProject.name = "lib-test"
    publications {
        create<MavenPublication>("libTest") {
            from(components["java"])
            artifactId = "lib-test"
        }
    }

That will generate a pom without the self-reference dependency.

However if I change for

rootProject.name = "lib-test"
    publications {
        create<MavenPublication>("libCore") {
            from(components["java"])
            artifactId = "lib-core"
        }
    }

Then it adds in the POM this :

    <dependency>
      <groupId>com.test</groupId>
      <artifactId>lib-core</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <scope>compile</scope>
      <optional>true</optional>
    </dependency>

That is strange as this problem appears only with kts and not groovy.

And as said in introduction, I have submodules, with 2 libs to publish so with different artifacts names than the project name.

Did I miss something or is it a bug ?

Thank you,

@gabrielittner
Copy link
Collaborator

This is unfortunately an issue in Gradle gradle/gradle#23354. Since there isn't much movement on that issue we should add a warning or error to the plugin in this case. That way at least no one will publish something with broken metadata.

@OlivierHartmann
Copy link
Author

Thank you very much for your very fast answer.
I understand that the workaround is to not modify the publication coordinates in the publication block. However, how to do when there is 2 submodules with publication of differently named artifacts ?

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