Skip to content

Commit

Permalink
Upgrade maven publish plugin to 0.21.0 and restore publishing (#773)
Browse files Browse the repository at this point in the history
Without this change, the recent Gradle upgrade (#743) resulted in the
following error while trying to publish to maven central:

```
> Task :jar-infer:jar-infer-cli:publishShadowPublicationToLocalRepository FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Some problems were found with the configuration of task ':jar-infer:jar-infer-cli:publishShadowPublicationToLocalRepository' (type 'PublishToMavenRepository').
  - Gradle detected a problem with the following location: '/Users/lazaro/Uber/NullAway/jar-infer/jar-infer-cli/build/libs/jar-infer-cli-0.10.11.jar.asc'.
    
    Reason: Task ':jar-infer:jar-infer-cli:publishShadowPublicationToLocalRepository' uses this output of task ':jar-infer:jar-infer-cli:signMavenPublication' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.
    
    Possible solutions:
      1. Declare task ':jar-infer:jar-infer-cli:signMavenPublication' as an input of ':jar-infer:jar-infer-cli:publishShadowPublicationToLocalRepository'.
      2. Declare an explicit dependency on ':jar-infer:jar-infer-cli:signMavenPublication' from ':jar-infer:jar-infer-cli:publishShadowPublicationToLocalRepository' using Task#dependsOn.
      3. Declare an explicit dependency on ':jar-infer:jar-infer-cli:signMavenPublication' from ':jar-infer:jar-infer-cli:publishShadowPublicationToLocalRepository' using Task#mustRunAfter.
```

This change fixes that issue and also upgrades
`com.vanniktech:gradle-maven-publish-plugin` to 0.21.0, the latest
compatible version (versions from 0.23.0 onwards don't seem to be
compatible with JDK8, and 0.22.0 gives a separate error).

Long term, we need to update the CI testing flow for publishing we added
in #768 to also cover jar signing workflows.
  • Loading branch information
lazaroclapp committed Jun 23, 2023
1 parent 37f4bb8 commit 2bfe823
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ buildscript {

dependencies {
classpath 'com.android.tools.build:gradle:7.3.0'
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.14.2'
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.21.0'
// This restriction is needed due to our mix of Android and Java modules;
// without it, the build fails with a weird error.
// See https://stackoverflow.com/questions/70217853/how-to-include-android-project-in-a-gradle-multi-project-build
Expand Down
4 changes: 4 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ POM_LICENCE_DIST=repo
POM_DEVELOPER_ID=uber
POM_DEVELOPER_NAME=Uber Technologies
POM_DEVELOPER_URL=https://uber.com

# Publishing configuration for vanniktech/gradle-maven-publish-plugin
SONATYPE_HOST=DEFAULT
RELEASE_SIGNING_ENABLED=true
32 changes: 30 additions & 2 deletions jar-infer/jar-infer-cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ dependencies {
}
}

java {
withJavadocJar()
withSourcesJar()
}

jar {
manifest {
attributes(
Expand All @@ -41,6 +46,7 @@ shadowJar {
shadowJar.dependsOn jar
assemble.dependsOn shadowJar


// We disable the default maven publications to make sure only
// our custom shadow publication is used. Since we use the empty
// classifier for our fat jar, it would otherwise clash with the
Expand All @@ -67,8 +73,8 @@ publishing {
// Since we are skipping the default maven publication, we append the `:sources` and
// `:javadoc` artifacts here. They are also required for Maven Central validation.
afterEvaluate {
artifact project.sourcesJar
artifact project.javadocsJar
artifact project.javaSourcesJar
artifact project.javadocJar
}
// The shadow publication does not auto-configure the pom.xml file for us, so we need to
// set it up manually. We use the opportunity to change the name and description from
Expand Down Expand Up @@ -98,5 +104,27 @@ publishing {
}
}
}
}

afterEvaluate {
// Below is a series of hacks needed to get publication to work with
// gradle-maven-publish-plugin >= 0.15.0 (itself needed after the upgrade to Gradle 8.0.2).
// Not sure why e.g. publishShadowPublicationToMavenCentralRepository must depend on signMavenPublication
// (rather than just signShadowPublication)
project.tasks.named('generateMetadataFileForMavenPublication').configure {
dependsOn 'javaSourcesJar'
dependsOn 'simpleJavadocJar'
}
project.tasks.named('signShadowPublication').configure {
dependsOn 'sourcesJar'
dependsOn 'simpleJavadocJar'
}
project.tasks.named('publishShadowPublicationToMavenCentralRepository').configure {
dependsOn 'signMavenPublication'
}
project.tasks.named('publishShadowPublicationToMavenLocal').configure {
dependsOn 'sourcesJar'
dependsOn 'simpleJavadocJar'
}
}
}

0 comments on commit 2bfe823

Please sign in to comment.