mockito / shipkit

Toolkit for shipping it used by Mockito library
http://shipkit.org
MIT License
158 stars 35 forks source link

Release normal jar and fat jar at the same time #869

Closed magx2 closed 4 years ago

magx2 commented 4 years ago

I could not find documentation how to release normal jar and fat jar at the same time. In my use case I would like to have one artifact as com.github.magx2:some-library and another with suffix -fat, com.github.magx2:some-library-fat.

mstachniuk commented 4 years ago

After a quick check, my suggestion is to create a separate submodule in your project called some-library-fat, include as compile/implementation scope the :some-library and define a jar like this:

dependencies {
    compile project(":some-library")
}

jar {
    manifest {
        attributes 'Main-Class': 'my.main.Class'
    }
    from {
        configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
    }
}
magx2 commented 4 years ago

Marcin thanks for help. I will definitely try your solution.

On the other hand I'm wondering if I can publish multiple artifacts with ship. Take a look on my configuration:

build.gradle https://github.com/magx2/jSuplaApi/blob/master/build.gradle#L71

publishing {
    publications {
        JarPublication(MavenPublication) {
            from components.java
            groupId group
            artifact jar
            artifactId project.name
            version project.version
        }
        FatJarPublication(MavenPublication) {
            from components.java
            groupId group
            artifact fatJar
            artifactId project.name + '-fat'
            version project.version
        }
    }
}

shipkit.gradle https://github.com/magx2/jSuplaApi/blob/master/gradle/shipkit.gradle#L16

allprojects {
    plugins.withId("org.shipkit.bintray") {
        bintray {
            publications = ['JarPublication', 'FatJarPublication']
            println publications
            key = System.getenv("BINTRAY_API_KEY")
            pkg {
                repo = "bigboy"
                user = "magx2"
                userOrg = "big-boy"
                name = 'jSuplaApi'
                licenses = ['MIT']
                labels = ['Supla', "IoT"]
            }
        }
    }
}

Don't you think this should work?

mstachniuk commented 4 years ago

It doesn't work :-( (I checked your build and publication history). But the trick with submodule work! The reason for that might be that Shipkit internally defines publications (including -source & -javadoc artifacts, pom customization, etc.) what is / might be in conflict with your settings. IMHO one module per publication is a cleaner solution.

magx2 commented 4 years ago

IMHO opinion it would be nice that shipkit recognizes and uses different publications but it might be discussion for another time.

For those who has similar problem I paste my solution:

  1. Create folder that has same as sub-module
  2. Create build.gradle with content
    
    plugins {
    id 'java'
    }

group = 'xxx.yyy.zzz'

dependencies { implementation rootProject }

jar { from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } }


3. Add new module to `settings.gradle`

You can find full change set here https://github.com/magx2/jSuplaApi/commit/8a6e0baa32765abf057688b9caf6dcdf7b39d023
geoHeil commented 4 years ago

I am also interested in this feature but do not want to create a separate submodule. Instead, I want to apply the shadow plugin https://github.com/johnrengelman/shadow

However, so far I did not manage to get the shadow stuff to publish.

geoHeil commented 4 years ago

https://gist.github.com/s1monw1/9bb3d817f31e22462ebdd1a567d8e78a#file-bintray-build-gradle-kts-L66 is working in a non multi-project build using the kotlin-DSL:


publishing {
    publications.invoke {
        publicationName(MavenPublication::class) {
            artifactId = artifactID
            artifact(shadowJar)
            pom.addDependencies()
        }
    }
}

However, I do not get this to compile in my own project. This fails for me with:

e: /Users/geoheil/development/projects/streaming-reference/build.gradle.kts:80:13: Unresolved reference: publicationName
e: /Users/geoheil/development/projects/streaming-reference/build.gradle.kts:81:17: Unresolved reference: artifactId
e: /Users/geoheil/development/projects/streaming-reference/build.gradle.kts:82:17: Unresolved reference: artifact
e: /Users/geoheil/development/projects/streaming-reference/build.gradle.kts:83:17: Unresolved reference: pom

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/geoheil/development/projects/streaming-reference/build.gradle.kts' line: 80

* What went wrong:
Script compilation errors:

  Line 80:             publicationName(MavenPublication::class) {
                       ^ Unresolved reference: publicationName

  Line 81:                 artifactId = project.name
                           ^ Unresolved reference: artifactId

  Line 82:                 artifact(shadowJar)
                           ^ Unresolved reference: artifact

  Line 83:                 pom.addDependencies()
                           ^ Unresolved reference: pom

4 errors
mockitoguy commented 4 years ago

@geoHeil, I recommend using following plugins (instead of the current Shipkit plugin):

The new plugins are small and allow you to fully control the publications. The new plugins reflect our future direction for Shipkit Gradle plugins (https://github.com/mockito/shipkit/blob/master/docs/design-specs/future-shipkit.md).