GradleUp / shadow

Gradle plugin to create fat/uber JARs, apply file transforms, and relocate packages for applications and libraries. Gradle version of Maven's Shade plugin.
https://www.gradleup.com/shadow/
Apache License 2.0
3.72k stars 392 forks source link

Obscure bug when using release plugin #231

Open itissid opened 8 years ago

itissid commented 8 years ago

I am using the shadow jar and the release plugin. Basically it is a jar task and makes the fat jar.

An obscure bug happens only when my repo is clean, release strategy final/dev: The publication task that uploads the jar gets confused about the name and tries adding a classifier string -all at the end:

 Invalid publication 'shadow': artifact file does not exist: '/home/sid/workspace/sandbox/build/libs/test-project-0.1.0-all.jar'

But the actual classifier is null and the real file is test-project-0.1.0.jar

This does not happen when release plugin is removed and also does not happen if the repo is dirty. The default versionStrategy is a custom one that increments the minor scope of the plugin. So what is it about the dirty repo that might effect the shadow plugin?

I would be happy to upload a test project for you to play with, if you have the bandwidth.

Gradle 2.12 Release plugin 1.4.2

I have also raised the request https://github.com/ajoberstar/gradle-git/issues/206

Shadow Version

1.2.3

Gradle Version

2.12

Expected Behavior

Upload the shadow jar with publishShadowPublicationToMavenRepository should succeed

Actual Behavior

the publishShadowPublicationToMavenRepository task gets confused about the classifier(which I add as null) when using the release plugin.

Gradle Build Script(s)

plugins {
    id 'java'
    id 'maven-publish'
    id "com.github.johnrengelman.shadow" version "1.2.3"
}

//version = "0.0.1-dev.32+1570692"
apply from: 'gradle/releaseWorkflow.gradle'

ext.lockCommitTag = "LockCommit-${new Date().format('yyyyMMddHHmmss')}"
description = """ A test project """

sourceCompatibility = 1.7
targetCompatibility = 1.7 

publishing {
    repositories {
        maven {
                url "${artifactory_contextUrl}/${artifactory_root_dir}/${artifactory_team_dir}/releases/"
                credentials {
                    username =  "${artifactory_user}"
                    password = "${artifactory_password}"
                }
        }
    }
    publications {
        shadow(MavenPublication) {
            from components.shadow
            artifactId = 'test-uber-jar'
        }
    }
}

jar {
    def manifestClasspath = configurations.runtime.collect { it.getName() }.join(' ')

    manifest {
        attributes  'Implementation-Title': implementationTitle,
                    'Built-By': System.getProperty('user.name'),
                    'Built-Date': new Date(),
                    'Built-JDK': System.getProperty('java.version'),
                    'Built-Gradle': gradle.gradleVersion,
                    'Class-Path': manifestClasspath 
    }
}

shadowJar {
        baseName = 'test-uber-jar'
        classifier = ''
}

The file for the release plugin under gradle/ sub dir is


apply plugin: 'org.ajoberstar.release-opinion'
apply plugin: 'org.ajoberstar.grgit'
apply plugin: 'org.ajoberstar.release-base'

import org.ajoberstar.grgit.Grgit
import org.ajoberstar.gradle.git.release.opinion.Strategies
import org.ajoberstar.gradle.git.release.opinion.Strategies
import org.ajoberstar.gradle.git.release.semver.StrategyUtil.*
import org.ajoberstar.gradle.git.release.semver.RebuildVersionStrategy
import static org.ajoberstar.gradle.git.release.semver.StrategyUtil.*
import org.ajoberstar.gradle.git.release.opinion.Strategies.Normal
import org.ajoberstar.gradle.git.release.opinion.Strategies.PreRelease
import org.ajoberstar.gradle.git.release.opinion.Strategies.BuildMetadata
import org.ajoberstar.gradle.git.release.semver.SemVerStrategy
import org.ajoberstar.gradle.git.release.semver.ChangeScope

ext{
    grgit = Grgit.open(project.file('.'))
    revision = grgit.head().abbreviatedId
}

release {
    System.setProperty("org.ajoberstar.grgit.auth.interactive.allow", "false")
    grgit = Grgit.open(project.file('.'))
    tasks.release.dependsOn 'build'

    versionStrategy RebuildVersionStrategy.INSTANCE
    versionStrategy Strategies.DEVELOPMENT
    versionStrategy Strategies.SNAPSHOT
    versionStrategy Strategies.PRE_RELEASE_ALPHA_BETA
    def SemVerStrategy finalWithMinorScope = Strategies.FINAL.copyWith(
        name: 'finalWithMinorScope',
        stages: ['finalWithMinorScope'] as SortedSet,
        normalStrategy: one(Normal.USE_SCOPE_PROP, Normal.USE_NEAREST_ANY, Normal.useScope(ChangeScope.MINOR)),
    )
    defaultVersionStrategy  = finalWithMinorScope
    tagStrategy {
        generateMessage = { version -> "Gradle release version: $version.version" }
    }
}

Content of Shadow JAR (jar tf <jar file> - post link to GIST if too long)

osboxes@osboxes:~/tr_workspace/sandbox$ jar tf build/libs/test-uber-jar-0.1.0.jar META-INF/ META-INF/MANIFEST.MF com/ com/tr/ com/tr/ap/ com/tr/ap/test_package/ com/tr/ap/test_package/HelloWorld.class

davidhesson commented 6 years ago

This is still broke and I'm using plugin id 'com.github.johnrengelman.shadow' version '2.0.4'