Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support config cache #824

Merged
merged 8 commits into from
Feb 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ Read the [User Guide](https://imperceptiblethoughts.com/shadow/)!

| Gradle Version | Shadow Version |
|----------------|----------------|
| 5.x | 5.2.0 - 6.0.0 |
| 6.x | 5.2.0 - 6.1.0 |
| 7.x | 7.0.0+ |
| 5.x | 5.2.0 - 6.0.0 |
| 6.x | 5.2.0 - 6.1.0 |
| 7.x | 7.0.0+ |
| 8.x | 8.0.0+ |

**NOTE**: Shadow v5.+ is compatible with Gradle 5.x - 6.x and Java 7 - 15 _only_, v6.1.0+ requires Java 8+.
42 changes: 16 additions & 26 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,35 +1,23 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation

buildscript {
repositories {
gradlePluginPortal()
mavenCentral()
}
dependencies {
classpath "com.gradle.publish:plugin-publish-plugin:0.16.0"
classpath 'org.ajoberstar:gradle-git-publish:3.0.0'
classpath "com.github.node-gradle:gradle-node-plugin:3.1.1"
}
}
import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
id 'groovy'
id 'project-report'
id 'idea'
id 'java-gradle-plugin'
id 'signing'
id 'com.gradle.plugin-publish' version '1.1.0'
id 'org.ajoberstar.git-publish' version '4.1.1'
id 'com.github.node-gradle.node' version '3.5.1'
}

// Remove the gradleApi so it isn't merged into the jar file.
configurations.named(JavaPlugin.API_CONFIGURATION_NAME) {
dependencies.remove(project.dependencies.gradleApi())
}

gradlePlugin {
automatedPublishing = false
}

apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: ShadowPlugin

apply from: file('gradle/docs.gradle')
apply from: file('gradle/publish.gradle')
Expand Down Expand Up @@ -71,32 +59,34 @@ idea {
}
}

tasks.named('ideaModule') {
notCompatibleWithConfigurationCache("https://github.com/gradle/gradle/issues/13480")
}

sourceCompatibility = '1.8'
targetCompatibility = '1.8'

task downloadDependencies(type: Exec) {
tasks.register('downloadDependencies', Exec) {
dependsOn configurations.testRuntimeClasspath
commandLine 'echo', 'Downloaded all dependencies'
}

tasks.build.dependsOn tasks.shadowJar
tasks.named('build') { dependsOn tasks.named('shadowJar') }

project.tasks.withType(JavaCompile) {
tasks.withType(JavaCompile).configureEach {
// This will be the default in Gradle 5.0
if (!options.compilerArgs.contains("-processor")) {
options.compilerArgs << '-proc:none'
}
}

project.tasks.withType(GroovyCompile) {
tasks.withType(GroovyCompile).configureEach {
// This will be the default in Gradle 5.0
if (!options.compilerArgs.contains("-processor")) {
options.compilerArgs << '-proc:none'
}
}

task relocateShadowJar(type: ConfigureShadowRelocation) {
target = tasks.shadowJar
tasks.named('shadowJar', ShadowJar) {
enableRelocation true
}

tasks.shadowJar.dependsOn tasks.relocateShadowJar
4 changes: 2 additions & 2 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ sourceSets {
}
}

project.tasks.withType(JavaCompile) {
tasks.withType(JavaCompile).configureEach {
// This will be the default in Gradle 5.0
if (!options.compilerArgs.contains("-processor")) {
options.compilerArgs << '-proc:none'
}
}

project.tasks.withType(GroovyCompile) {
tasks.withType(GroovyCompile).configureEach {
// This will be the default in Gradle 5.0
if (!options.compilerArgs.contains("-processor")) {
options.compilerArgs << '-proc:none'
Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=2g
org.gradle.parallel=true
org.gradle.caching=true
org.gradle.caching=true
org.gradle.unsafe.configuration-cache=true
15 changes: 8 additions & 7 deletions gradle/docs.gradle
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
def javaApiUrl = 'http://docs.oracle.com/javase/17/docs/api'
def groovyApiUrl = "http://docs.groovy-lang.org/2.4.7/html/gapi/"
def javaApiUrl = 'https://docs.oracle.com/javase/17/docs/api'
def groovyApiUrl = "https://docs.groovy-lang.org/2.4.7/html/gapi/"

tasks.withType(Javadoc) {
tasks.withType(Javadoc).configureEach {
classpath += project.configurations.shadow
options.links(javaApiUrl, groovyApiUrl)
if (JavaVersion.current().java8Compatible) {
options.addStringOption('Xdoclint:none', '-quiet')
}
}

task javadocJar(type: Jar, dependsOn: javadoc) {
tasks.register('javadocJar', Jar) {
dependsOn javadoc
archiveClassifier.set('javadoc')
from 'build/docs/javadoc'
}

task sourcesJar(type: Jar) {
tasks.register('sourcesJar', Jar) {
archiveClassifier.set('sources')
from sourceSets.main.allSource
}

project.tasks.groovydoc {
tasks.named('groovydoc') {
classpath += project.configurations.shadow
}

build.dependsOn javadocJar, sourcesJar
tasks.named('build') { dependsOn javadocJar, sourcesJar }
6 changes: 3 additions & 3 deletions gradle/ghPages.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.apache.tools.ant.filters.ReplaceTokens
apply plugin: 'org.ajoberstar.git-publish'

if (project.hasProperty('githubToken')) {
System.setProperty('org.ajoberstar.grgit.auth.username', project.githubToken)
System.setProperty('org.ajoberstar.grgit.auth.username', project.githubToken)
}

gitPublish {
Expand All @@ -23,5 +23,5 @@ gitPublish {
}
}

tasks.gitPublishCopy.dependsOn yarn_build
tasks.gitPublishCopy.dependsOn groovydoc
tasks.named('gitPublishCopy') { dependsOn yarn_build }
tasks.named('gitPublishCopy') { dependsOn groovydoc }
85 changes: 15 additions & 70 deletions gradle/publish.gradle
Original file line number Diff line number Diff line change
@@ -1,101 +1,44 @@
apply plugin: 'maven-publish'
apply plugin: "com.gradle.plugin-publish"

group = 'com.github.johnrengelman'

def versionString = file('src/main/resources/shadow-version.txt').text.trim()
if (System.env.CIRCLE_TAG && System.env.CIRCLE_TAG =~ /^\d\.\d\.\d$/) {
version = System.env.CIRCLE_TAG
} else {
version = versionString
version = file('src/main/resources/shadow-version.txt').text.trim()
if (!version.endsWith("-SNAPSHOT")) {
version = version + "-SNAPSHOT"
}
}

ext.isSnapshot = version.endsWith("SNAPSHOT")

def pomConfig = {
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
developers {
developer {
id 'jengelman'
name 'John Engelman'
email '[email protected]'
}
}
}

publishing {
publications {
plugin(MavenPublication) {
shadow.component(it)
artifact sourcesJar
artifact javadocJar

pom.withXml {
def root = asNode()
root.appendNode('description', 'Gradle plugin to combine/relocate dependencies in a single Jar.')
root.children().last() + pomConfig
}
}
}
}

// Workaround for configuring the artifact that publish-plugins uses: https://github.com/JLLeitschuh/ktlint-gradle/blob/master/plugin/build.gradle.kts
// Need to move publishing configuration into afterEvaluate {}
// to override changes done by "com.gradle.plugin-publish" plugin in afterEvaluate {} block
// See PublishPlugin class for details
afterEvaluate {
publishing {
publications {
withType(MavenPublication) {
// Special workaround to publish shadow jar instead of normal one. Name to override peeked here:
// https://github.com/gradle/gradle/blob/master/subprojects/plugin-development/src/main/java/org/gradle/plugin/devel/plugins/MavenPluginPublishPlugin.java#L73
if (name == "pluginMaven") {
setArtifacts([
tasks.shadowJar,
tasks.sourcesJar,
tasks.javadocJar
])
}
}
}
}
}

tasks.whenTaskAdded {
tasks.configureEach {
if (name == "publishPluginJar" || name == "generateMetadataFileForPluginMavenPublication") {
dependsOn(tasks.named("shadowJar"))
}
}

pluginBundle {
gradlePlugin {
website = 'https://github.com/johnrengelman/shadow'
vcsUrl = 'https://github.com/johnrengelman/shadow'
tags = ['onejar', 'shade', 'fatjar', 'uberjar']

plugins {
shadowPlugin {
id = 'com.github.johnrengelman.shadow'
implementationClass = 'com.github.jengelman.gradle.plugins.shadow.ShadowPlugin'
displayName = 'Shadow Plugin'
description = "Gradle plugin to create fat/uber JARs, apply file transforms, and relocate packages for applications and libraries. Gradle version of Maven's Shade plugin."
tags.set(['onejar', 'shade', 'fatjar', 'uberjar'])
}
}
}

publishPlugins { task ->
tasks.named('publishPlugins') {
doFirst {
if (isSnapshot) {
if (version.endsWith("SNAPSHOT")) {
throw new GradleException('Cannot publish SNAPSHOT versions to Plugin Portal!')
}
}
notCompatibleWithConfigurationCache("https://github.com/gradle/gradle/issues/21283")
}

signing {
Expand All @@ -105,12 +48,14 @@ signing {
def signingPassword = findProperty("signingPassword")
useInMemoryPgpKeys(signingKey, signingPassword)
}
required {
gradle.taskGraph.hasTask("artifactoryPublish")
}
sign publishing.publications.plugin
required = gradle.taskGraph.hasTask("artifactoryPublish")
sign(publishing.publications)
}

tasks.withType(Sign).configureEach {
notCompatibleWithConfigurationCache("https://github.com/gradle/gradle/issues/13470")
}

task release() {
tasks.register('release') {
dependsOn 'assemble', 'publishPlugins', 'gitPublishPush'
}
6 changes: 4 additions & 2 deletions gradle/vuepress.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ node {
yarnVersion = '1.5.1'
}

tasks.yarn_build.inputs.files project.fileTree('src/docs')
tasks.yarn_build.outputs.dir project.file('build/site')
tasks.named('yarn_build') {
inputs.files project.fileTree('src/docs')
outputs.dir project.file('build/site')
}
9 changes: 9 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
pluginManagement {
repositories {
mavenCentral()
gradlePluginPortal()
}
}

plugins {
id 'com.gradle.enterprise' version '3.12.3'
}
Expand All @@ -22,4 +29,6 @@ gradleEnterprise {
}
}

enableFeaturePreview("STABLE_CONFIGURATION_CACHE")

rootProject.name = 'shadow'
11 changes: 4 additions & 7 deletions src/docs/configuration/relocation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,12 @@ dependency so the tasks execute in the correct order.

```groovy
// Configure Auto Relocation
import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation

task relocateShadowJar(type: ConfigureShadowRelocation) {
target = tasks.shadowJar
prefix = "myapp" // Default value is "shadow"
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

tasks.named('shadowJar', ShadowJar) {
enableRelocation true
relocationPrefix "myapp"
}

tasks.shadowJar.dependsOn tasks.relocateShadowJar
```

> Configuring package auto relocation can add significant time to the shadow process as it will process all dependencies
Expand Down
8 changes: 3 additions & 5 deletions src/docs/plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ A simple Gradle plugin can use this feature by applying the `shadow` plugin and
to execute before the `shadowJar` tasks:

```groovy no-plugins
import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
id 'com.github.johnrengelman.shadow' version '@version@'
Expand All @@ -38,11 +38,9 @@ dependencies {
implementation 'org.codehaus.plexus:plexus-utils:2.0.6'
}

task relocateShadowJar(type: ConfigureShadowRelocation) {
target = tasks.shadowJar
tasks.named('shadowJar', ShadowJar) {
enableRelocation true
}

tasks.shadowJar.dependsOn tasks.relocateShadowJar
```

Note that the `localGroovy()` and `gradleApi()` dependencies are added to the `shadow` configuration instead of the
Expand Down
Loading