mardi 28 avril 2020

gradle publishing with kotlin dsl with artifactId != project.name for spring-cloud-contract 3.0.0.M1 Milestone

I have a gradle kotlin dsl multi-project setup where the archivesBaseName and therefore artifactId is not equal to the subproject.name.

I struggle with publishing (here publishToMavenLocal) as artifact(verifierStubsJar) is complaining with

Cannot convert the provided notation to an object of type MavenArtifact: task ':microservice:verifierStubsJar'.
The following types/formats are supported:
  - Instances of MavenArtifact.
  - Instances of AbstractArchiveTask, for example jar.
  - Instances of PublishArtifact
  - Maps containing a 'source' entry, for example [source: '/path/to/file', extension: 'zip'].
  - Anything that can be converted to a file, as per Project.file()

also the configurations { ... provider.get().outgoing.artifact(bootJar) ... }

is complaining with:

   > Artifact minimal_microservice-0.1.0.NIGHTLY.jar wasn't produced by this build.

the publishing for my gradle kotlin dsl looks like this:

// Starting from Gradle 6.2, Gradle performs a sanity check before uploading, to make sure you don’t
// upload stale files (files produced by another build). This introduces a problem with Spring Boot
// applications which are uploaded using the components.java component:
// Artifact my-application-0.0.1-SNAPSHOT.jar wasn't produced by this build.
// This is caused by the fact that the main jar task is disabled by the Spring Boot application, and the
// component expects it to be present. Because the bootJar task uses the same file as the main jar task by default,
configurations {
    val jar by tasks.existing
    val bootJar by tasks.existing
    listOf(apiElements, runtimeElements).forEach { provider ->
        provider.get().outgoing.artifacts.removeIf {
            it.buildDependencies.getDependencies(null).contains(jar)
        }
//        provider.get().outgoing.artifact(bootJar)        // <-- why does this not work???
        println(String.format("%s/libs/%s-%s.jar", project.buildDir, archivesBaseName, version))
        provider.get().outgoing.artifact(File(String.format("%s/libs/%s-%s.jar", project.buildDir, archivesBaseName, version)))
    }
}
configure<org.gradle.api.publish.PublishingExtension> {
    publications {
        val archivesBaseName: String by project.extra
        val theVersion = version as String
        create<MavenPublication>("maven") {
            groupId = project.rootProject.group as String?
//            artifactId = archivesBaseName
            version = theVersion
            from(components["java"])
            afterEvaluate {
                artifactId = tasks.bootJar.get().archiveBaseName.get()
            }
        }
        create<MavenPublication>("stubs") {
            groupId = project.rootProject.group as String?
//            artifactId = archivesBaseName // + "-stubs"
            version = theVersion
            val verifierStubsJar by tasks.existing
            artifact(verifierStubsJar)               // <-- this line gives me the above error
            afterEvaluate {
                artifactId = tasks.bootJar.get().archiveBaseName.get()
            }
        }
    }
}

any idea how to (with gradle kotlin dsl)?

a) adjust the configurations { ... } part for a customarchivesBaseName`

b) get the MavenPublication "stubs" artifact from generatedverifierStubsJar`

Aucun commentaire:

Enregistrer un commentaire