Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to script Gradle in order to publish shadowjar into Artifactory

Tags:

java

gradle

build

I am using shadowJar in my java project. I would like to push the outcome into artifactory.

My gradle script look like this, I am not sure how to connect the dots:

shadowJar {
    baseName = 'com.mycompany.myapp'
    manifest {
        attributes 'Main-Class': 'myapp.starter'
    }
}


  ]
    apply plugin: 'java'
    apply plugin: 'idea'
    apply plugin: 'maven'
    apply plugin: 'com.github.johnrengelman.shadow'


    // rep for the project
    repositories {
        mavenCentral()
        maven {
            url 'http://repo.company:8081/artifactory/libs-release'
            credentials {
                username = "${repo_user}"
                password = "${repo_password}"
            }
        }
        maven {
            url 'http://repo.company:8081/artifactory/libs-snapshot'
            credentials {
                username = "${repo_user}"
                password = "${repo_password}"
            }
        }

}


publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java

            artifact sourceJar {
                classifier "sources"
            }
        }
    }
}

How do I code gradle to take the shadowjar file?

thanks, ray.

like image 640
rayman Avatar asked Feb 01 '16 13:02

rayman


People also ask

Where can I publish gradle plugin?

But if you want the plugin to be available to anyone in the world, i.e. public, then you should publish it to the Gradle Plugin Portal, a centralized, searchable repository dedicated to Gradle plugins.

What is a shadow jar?

Shaded jar (or shaded classes) - usually refers to a process of changing classes bytecode to change packages names of the classes, and also modify were it is used in the jar. It is used to link classes to a specific version of other classes and avoid versions collisions. It can be created by Maven Shade Plugin.


1 Answers

It's a bit late, but I'd like to show you how I got it to work. Maybe it helps someone stumbling across this question as I did:

build.gradle.kts:

plugins {
    java
    `maven-publish`
    id("com.github.johnrengelman.shadow") version "5.1.0"
}
publishing {
    publications {
        create<MavenPublication>("maven") {
            from(components["java"])
            artifact(tasks["shadowJar"])
        }
    }
    repositories {
        maven {
          /* ... */
        }
    }
}

The example above is written in Kotlin, if you prefer Groovy, you would need to write this instead:

build.gradle:

publishing {
  publications {
    shadow(MavenPublication) {
      from components.java
      artifact shadowJar
    }
  }
}

(found it here: https://libraries.io/github/johnrengelman/shadow)

like image 182
chrset Avatar answered Sep 23 '22 19:09

chrset