injecteer
injecteer

Reputation: 20707

Publish only JAR to maven repo

I want to upload a generated jar file to packagecloud.io.

My shortened build.gradle:

jar {
  archiveName "$project.name-$project.version-SNAPSHOT.jar"
}

distTar {
  archiveName 'dist.tar'
}

//project.configurations.archives.artifacts.clear()
artifacts {
  archives( file( "$buildDir/libs/$project.name-$project.version-SNAPSHOT.jar" ) )
}

uploadArchives {
  repositories.mavenDeployer {
    pom.version = project.version + '-SNAPSHOT'
    configuration = configurations.deployerJars
    repository( url:'packagecloud+https://packagecloud.io/mycompany/central' ){
        authentication password:pw
    }
  }
}

jar.finalizedBy uploadArchives

when I run gradlew distTar, the jar file is generated along with tar, and is uploaded to the repo, but the build fails with exceptions:

> Task :compileJava NO-SOURCE
> Task :compileGroovy UP-TO-DATE
> Task :processResources UP-TO-DATE
> Task :classes UP-TO-DATE
> Task :jar
> Task :startScripts
> Task :distTar

> Task :uploadArchives
Could not transfer artifact io.mozaiq:feature-state-verticle:pom:0.1-20190509.110559-1 from/to remote (packagecloud+https://packagecloud.io/mozaiq/central): Upload failed: {"error":"Validation failed: Unknown Java::Version::UnsupportedPackaging"}
Could not transfer artifact io.mozaiq:feature-state-verticle:tar:0.1-20190509.110559-1 from/to remote (packagecloud+https://packagecloud.io/mozaiq/central): Upload failed: {"error":"Could not understand this request, please contact [email protected]"}

> Task :uploadArchives FAILED

so, for some reason it tries to upload not only the jar file, but all the artefacts generated.

How can I restrict publishing to a jar file only?

Upvotes: 0

Views: 922

Answers (1)

M.Ricciuti
M.Ricciuti

Reputation: 12116

Based on answers from a similar question and this post from Gradle forum: a solution would be to exclude all artifacts which are not 'jar' from the archives configuration. This way, the uploadArchives will only upload Jar artifacts, skipped all other produced artifacts/

configurations.archives.artifacts.removeAll{
    it.extension != 'jar'
}

This is similar to your own solution which is based on artifact 'type' .

Upvotes: 1

Related Questions