Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Publish custom jar output with gradle?

I have a gradle build script that retrieves a number of common dependencies and creates a "fat jar" with them all combined.

gradle fatJar uploadArchives

However the uploadArchives step afterwards does not use the jar generated and instead overwrites it with a default jar that has none of the dependencies.

How can I specify the publish step to use the "fat jar" and not overwrite the jar created?

apply plugin: 'java'
apply plugin: 'maven'

version '1.2.3'

sourceSets {
   main {
      resources.srcDirs = ["resources"]  
   }
}

repositories {
    mavenCentral()
}
dependencies {
  runtime 'commons-cli:commons-cli:1.3.1'                            
  ....
  runtime 'xerces:xercesImpl:2.11.0'

}


//create a single Jar with all dependencies
task fatJar(type: Jar) {
    manifest {
        attributes 'Implementation-Title': 'Some common jars',  
            'Implementation-Version': version
    }
    from { configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar
}



uploadArchives {
   repositories {

      mavenDeployer {
        repository(url: "http://localhost:8081/artifactory/org-sandbox") {
            authentication(userName: "admin", password:"password")
        }
        pom.groupId = 'org.something'
      }
   }

}
like image 702
Matt--12345 Avatar asked Sep 25 '22 06:09

Matt--12345


1 Answers

Following RaGe's suggestion, I switched to maven-publish which allows specifying the artifact ( by task name).. This worked.

publishing {
  publications {
     maven(MavenPublication) {

       groupId 'org.something'

       artifact fatJar 
    }
 }

 repositories { 
  maven {
    url "http://localhost:8081/artifactory/sandbox"
    credentials { 
       username 'admin' 
       password 'password' 
    }
  }

}

like image 86
Matt--12345 Avatar answered Sep 30 '22 00:09

Matt--12345