2

It's not immediately intuitive on how to publish a fat JAR to JitPack because the shadow docs don't have a section for JitPack and the JitPack docs don't have a section on fat jars.

All the docs say is that if you include maven-publish then they will execute the task publishToMavenLocal.

Normally a shadowJar fat jar is created via gradle shadowjar but the build command on JitPack is not configurable therefore we must modify our publishToMavenLocal to use shadowJar.

fIwJlxSzApHEZIl
  • 11,861
  • 6
  • 62
  • 71

2 Answers2

3

I made a support request with JitPack and they've come back with the following code which I have tested to be working as of 2018/04/12:

plugins {
    id "com.github.johnrengelman.shadow" version "2.0.2"
}

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

group = 'com.github.jitpack-io'

repositories {
  mavenCentral()
}

dependencies {
  compile 'com.google.guava:guava:18.0'
  testCompile 'junit:junit:4.12'
}

task sourcesJar(type: Jar, dependsOn: classes) {
    classifier = 'sources'
    from sourceSets.main.allSource
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir
}

shadowJar {
    archiveName = "$baseName-$version.$extension"
}

artifacts {
    archives sourcesJar
    archives javadocJar
    archives shadowJar
}

They've published the code via GitHub.

It can also be combined with the gradle wrapper:

allprojects {
    task wrapper(type: Wrapper) {
        gradleVersion = '4.4'
        distributionType = Wrapper.DistributionType.ALL
    }
}
fIwJlxSzApHEZIl
  • 11,861
  • 6
  • 62
  • 71
2

probably a little to late but I got it running but just adding the artifact into the publish part like this:

publishing {
publications {
    mavenJava(MavenPublication) {
        groupId project.group
        artifactId project.name
        version project.version
        from components.java
        artifact sourceJar {
            classifier "sources"
        }
        artifact shadowJar
    }
}....
Jorge Machado
  • 752
  • 1
  • 8
  • 28