1
votes

I'm struggling with deploying the war file to Nexus repository using Jenkinsfile via Gradle task.

The war is being created successfully. I have also no problem with deploying JARs (since there are examples everywhere how to do it).

So I have this publishing section in my build.grade:

publishing {
    repositories {
        maven {
            URI releasesUrl = new URI("${UploadURL}/repository/releases")
            URI snapshotsUrl = new URI("${UploadURL}/repository/snapshots")

            afterEvaluate {
                url version.endsWith("SNAPSHOT") ? snapshotsUrl : releasesUrl
            }
            credentials {
                username "${user}"
                password "${password}"
            }
        }
    }
    publications {
        mavenWeb(MavenPublication) {
            from components.web
            artifact war.archivePath
        }
    }
}

With pluggins:

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'

The URL for repositories is also specified in the build script correctly (test publish with the jar works just fine)

And the Jenkinsfile:

stage ('Publish war') {
    steps {
        sh "sh gradlew publish"
    }
}

Currently I'm getting this error from jenkins build:

Task :publishMavenWebPublicationToMavenRepository FAILED

FAILURE: Build failed with an exception.

What went wrong: Execution failed for task ':publishMavenWebPublicationToMavenRepository'. Failed to publish publication 'mavenWeb' to repository 'maven' Invalid publication 'mavenWeb': multiple artifacts with the identical extension and classifier ('war', 'null').

I'm quite sure that the problem is within "publications" part of Gradle task. For publishing the Jars I have been using it like this:

[...]
publications {
    mavenJava(MavenPublication) {
        from components.java
        artifact sourceJar
    }
}
[...]


task sourceJar(type: Jar) {
    classifier 'sources'
    from sourceSets.main.java
}

I do not know how to configure from, artifact and classifier for this task. I do not even know if all of these parameters should be configured... Could anyone help me with that?

1

1 Answers

1
votes

It turned out, that the origin of the problem was this section:

afterEvaluate {
    url version.endsWith("SNAPSHOT") ? snapshotsUrl : releasesUrl
} 

This feature works with Gradle 5.X version however, I was using Gradle 4.8. That lead to null instead of propper url value... Unfortunately, it took a while since the exception message does not suggest where the problem was.