-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'feature.shadow' convention plugin (#86)
Signed-off-by: Jendrik Johannes <jendrik.johannes@gmail.com>
- Loading branch information
Showing
5 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Conventions for 'com.gradleup.shadow' to be used to build a fat Jar of an application |
26 changes: 26 additions & 0 deletions
26
src/main/kotlin/org.hiero.gradle.feature.shadow.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import com.github.jengelman.gradle.plugins.shadow.internal.DefaultDependencyFilter | ||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar | ||
|
||
plugins { | ||
id("application") | ||
id("com.gradleup.shadow") | ||
} | ||
|
||
tasks.withType<ShadowJar>().configureEach { | ||
group = "shadow" | ||
mergeServiceFiles() | ||
|
||
manifest { attributes("Multi-Release" to "true") } | ||
|
||
// There is an issue in the shadow plugin that it automatically accesses the | ||
// files in 'runtimeClasspath' while Gradle is building the task graph. | ||
// See: https://github.com/GradleUp/shadow/issues/882 | ||
dependencyFilter = NoResolveDependencyFilter() | ||
} | ||
|
||
class NoResolveDependencyFilter : DefaultDependencyFilter(project) { | ||
override fun resolve(configuration: FileCollection): FileCollection { | ||
return configuration | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package org.hiero.gradle.test | ||
|
||
import org.assertj.core.api.Assertions.assertThat | ||
import org.gradle.testkit.runner.TaskOutcome | ||
import org.hiero.gradle.test.fixtures.GradleProject | ||
import org.junit.jupiter.api.Test | ||
|
||
class ShadowTest { | ||
|
||
@Test | ||
fun `can build a fatjar for an application`() { | ||
val p = GradleProject().withMinimalStructure() | ||
p.dependencyVersionsFile( | ||
""" | ||
plugins { | ||
id("org.hiero.gradle.base.lifecycle") | ||
id("org.hiero.gradle.base.jpms-modules") | ||
} | ||
dependencies.constraints { | ||
api("org.apache.commons:commons-lang3:3.14.0") { because("org.apache.commons.lang3") } | ||
} | ||
""" | ||
.trimIndent() | ||
) | ||
p.moduleInfoFile( | ||
""" | ||
module org.hiero.product.module.a { | ||
requires org.apache.commons.lang3; | ||
}""" | ||
.trimIndent() | ||
) | ||
p.moduleBuildFile( | ||
""" | ||
plugins { | ||
id("org.hiero.gradle.module.application") | ||
id("org.hiero.gradle.feature.shadow") | ||
} | ||
application { | ||
mainClass = "org.hiero.product.module.a.ModuleA" | ||
} | ||
""" | ||
.trimIndent() | ||
) | ||
|
||
val result = p.run("assemble") | ||
|
||
assertThat(result.task(":module-a:shadowJar")?.outcome).isEqualTo(TaskOutcome.SUCCESS) | ||
} | ||
} |