Skip to content

Commit

Permalink
Add 'feature.shadow' convention plugin (#86)
Browse files Browse the repository at this point in the history
Signed-off-by: Jendrik Johannes <jendrik.johannes@gmail.com>
  • Loading branch information
jjohannes authored Jan 17, 2025
1 parent d395ad2 commit 96aab1c
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* update spotless-plugin-gradle to 7.0.2 (improves configuration cache compatibility)
* update dependency-analysis-gradle-plugin to 2.7.0 (addresses Gradle deprecation)
* add 'feature.legacy-classpath' convention plugin
* add 'feature.shadow' convention plugin

## Version 0.3.0

Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies {
implementation("com.google.protobuf:protobuf-gradle-plugin:0.9.4")
implementation("com.gradle.publish:plugin-publish-plugin:1.3.0")
implementation("com.gradle:develocity-gradle-plugin:3.19")
implementation("com.gradleup.shadow:shadow-gradle-plugin:8.3.5")
implementation(
"gradle.plugin.com.google.cloud.artifactregistry:artifactregistry-gradle-plugin:2.2.2"
)
Expand Down
1 change: 1 addition & 0 deletions src/main/descriptions/org.hiero.gradle.feature.shadow.txt
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 src/main/kotlin/org.hiero.gradle.feature.shadow.gradle.kts
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
}
}
50 changes: 50 additions & 0 deletions src/test/kotlin/org/hiero/gradle/test/ShadowTest.kt
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)
}
}

0 comments on commit 96aab1c

Please sign in to comment.