Skip to content
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
99 changes: 45 additions & 54 deletions docs/application-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@ configure additional tasks for running the shadowed JAR and creating distributio
Just like the normal `jar` task, when the `application` plugin is applied, the `shadowJar` manifest will be
configured to contain the `Main-Class` attribute with the value specified in the project's `mainClassName` attribute.

```groovy
// Using Shadow with Application Plugin
plugins {
id 'java'
id 'application'
id 'com.gradleup.shadow'
}

application {
mainClass = 'myapp.Main'
}
```
plugins {
id 'java'
id 'application'
id 'com.gradleup.shadow'
}

application {
mainClass = 'myapp.Main'
}

## Running the Shadow JAR

Expand All @@ -28,24 +25,21 @@ The `runShadow` task is a [`JavaExec`](https://docs.gradle.org/current/dsl/org.g
task that is configured to execute `java -jar myproject-all.jar`.
It can be configured the same as any other `JavaExec` task.

```groovy
// Configuring the runShadow Task
plugins {
id 'java'
id 'application'
id 'com.gradleup.shadow'
}

application {
mainClass = 'myapp.Main'
// Optionally, you can add default JVM arguments to the start scripts like this:
applicationDefaultJvmArgs = ['--add-opens=java.base/java.lang=ALL-UNNAMED']
}

tasks.named('runShadow', JavaExec) {
args 'foo'
}
```
plugins {
id 'java'
id 'application'
id 'com.gradleup.shadow'
}

application {
mainClass = 'myapp.Main'
// Optionally, you can add default JVM arguments to the start scripts like this:
applicationDefaultJvmArgs = ['--add-opens=java.base/java.lang=ALL-UNNAMED']
}

tasks.named('runShadow', JavaExec) {
args 'foo'
}

## Distributing the Shadow JAR

Expand All @@ -60,30 +54,27 @@ files for a distribution to `build/install/<project name>-shadow/`.

You can also add more files into the distribution like:

```groovy
// Add extra files to the distribution
plugins {
id 'java'
id 'application'
id 'com.gradleup.shadow'
}

application {
mainClass = 'myapp.Main'
// Optionally, you can include `some/dir` files in the distribution like this:
applicationDistribution.from('some/dir') {
include '*.txt'
}
}

// `shadow` is the name of the distribution created by Shadow plugin
distributions.named('shadow') {
// Optionally, you can add more files into extra directory in the distribution like this:
contents.from('extra/echo.sh') {
into 'extra'
}
}
```
plugins {
id 'java'
id 'application'
id 'com.gradleup.shadow'
}

application {
mainClass = 'myapp.Main'
// Optionally, you can include `some/dir` files in the distribution like this:
applicationDistribution.from('some/dir') {
include '*.txt'
}
}

// `shadow` is the name of the distribution created by Shadow plugin
distributions.named('shadow') {
// Optionally, you can add more files into extra directory in the distribution like this:
contents.from('extra/echo.sh') {
into 'extra'
}
}

View [the official doc described](https://docs.gradle.org/current/userguide/distribution_plugin.html#distribution_plugin)
for more information about configuring distributions.
75 changes: 32 additions & 43 deletions docs/configuration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,11 @@ file at: `build/libs/myApp-1.0-all.jar`

As with all `Jar` tasks in Gradle, these values can be overridden:

```groovy
// Output to build/libs/shadow.jar
tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
archiveBaseName = 'shadow'
archiveClassifier = ''
archiveVersion = ''
}
```
tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
archiveBaseName = 'shadow'
archiveClassifier = ''
archiveVersion = ''
}

## Configuring the Runtime Classpath

Expand All @@ -50,11 +47,9 @@ in the JAR manifest.
The value of the `Class-Path` entry is the name of all dependencies resolved in the `shadow` configuration
for the project.

```groovy
dependencies {
shadow 'junit:junit:3.8.2'
}
```
dependencies {
shadow 'junit:junit:3.8.2'
}

Inspecting the `META-INF/MANIFEST.MF` entry in the JAR file will reveal the following attribute:

Expand All @@ -71,13 +66,11 @@ Beyond the automatic configuration of the `Class-Path` entry, the `shadowJar` ma
First, the manifest for the `shadowJar` task is configured to __inherit__ from the manifest of the standard `jar` task.
This means that any configuration performed on the `jar` task will propagate to the `shadowJar` tasks.

```groovy
tasks.named('jar', Jar) {
manifest {
attributes 'Class-Path': '/libs/a.jar'
}
}
```
tasks.named('jar', Jar) {
manifest {
attributes 'Class-Path': '/libs/a.jar'
}
}

Inspecting the `META-INF/MANIFEST.MF` entry in the JAR file will reveal the following attribute:

Expand All @@ -88,33 +81,29 @@ Class-Path: /libs/a.jar
If it is desired to inherit a manifest from a JAR task other than the standard `jar` task, the `inheritFrom` methods
on the `shadowJar.manifest` object can be used to configure the upstream.

```groovy
def testJar = tasks.register('testJar', Jar) {
manifest {
attributes 'Description': 'This is an application JAR'
}
}

tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
manifest.inheritFrom(testJar.get().manifest)
}
```
def testJar = tasks.register('testJar', Jar) {
manifest {
attributes 'Description': 'This is an application JAR'
}
}

tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
manifest.inheritFrom(testJar.get().manifest)
}

## Adding Extra Files

The `shadowJar` task is a subclass of the `Jar` task, which means that the
[from](https://docs.gradle.org/current/dsl/org.gradle.jvm.tasks.Jar.html#org.gradle.jvm.tasks.Jar:from(java.lang.Object,%20groovy.lang.Closure))
method can be used to add extra files.

```groovy
tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
from('extra.jar') {
// Copy extra.jar file (without unzipping) into META-INF/ in the shadowed JAR.
into('META-INF')
}
from('Foo') {
// Copy Foo file into Bar/ in the shadowed JAR.
into('Bar')
}
}
```
tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
from('extra.jar') {
// Copy extra.jar file (without unzipping) into META-INF/ in the shadowed JAR.
into('META-INF')
}
from('Foo') {
// Copy Foo file into Bar/ in the shadowed JAR.
into('Bar')
}
}
Loading