@@ -1054,4 +1054,104 @@ class ShadowPluginSpec extends PluginSpecification {
10541054 JarFile jar = new JarFile(output)
10551055 assert jar.entries().collect().findAll { it.name.endsWith(' . class' ) }.size() == 1
10561056 }
1057+
1058+ @Issue("https://github.com/GradleUp/shadow/issues/882")
1059+ def ' compat gradle artifact transform' () {
1060+ given:
1061+ file(' settings. gradle' ) << "include(' app' , ' lib' )\n "
1062+ file("lib/build.gradle") << """
1063+ plugins {
1064+ id ' java- library'
1065+ }
1066+ """.stripIndent()
1067+
1068+ file("lib/src/main/java/com/company/Utils.java") << """
1069+ package com.company;
1070+
1071+ public class Utils {
1072+ public static void foo() {
1073+ System.out.println("bar");
1074+ }
1075+ }
1076+ """.stripIndent()
1077+
1078+ file("app/build.gradle") << """
1079+ import org.gradle.api.artifacts.transform.TransformParameters
1080+ import org.gradle.api.artifacts.transform.TransformAction
1081+ import org.gradle.api.artifacts.transform.TransformOutputs
1082+ import org.gradle.api.artifacts.transform.InputArtifact
1083+ import org.gradle.api.file.FileSystemLocation
1084+ import org.gradle.api.provider.Provider
1085+
1086+ plugins {
1087+ id ' application'
1088+ id ' com. gradleup. shadow'
1089+ }
1090+
1091+ application {
1092+ mainClass = ' com.company.Main '
1093+ }
1094+
1095+ dependencies {
1096+ implementation project(' :lib' )
1097+ }
1098+
1099+ def transformedAttribute = Attribute.of(' custom- transformed' , Boolean)
1100+
1101+ dependencies {
1102+ attributesSchema {
1103+ attribute(transformedAttribute)
1104+ }
1105+ artifactTypes.maybeCreate(' jar' ).attributes.attribute(transformedAttribute, false)
1106+ }
1107+
1108+ dependencies {
1109+ registerTransform(CustomTransformAction) {
1110+ from.attribute(Attribute.of(' artifactType' , String), ' jar' ).attribute(transformedAttribute, false)
1111+ to.attribute(Attribute.of(' artifactType' , String), ' jar' ).attribute(transformedAttribute, true)
1112+ }
1113+ }
1114+
1115+ tasks.named(' shadowJar' , com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
1116+ configurations = [project.configurations.runtimeClasspath]
1117+ }
1118+
1119+ configurations.runtimeClasspath {
1120+ attributes.attribute(transformedAttribute, true)
1121+ }
1122+
1123+ abstract class CustomTransformAction implements TransformAction<TransformParameters.None> {
1124+ @InputArtifact abstract Provider<FileSystemLocation> getInputArtifact()
1125+
1126+ @Override
1127+ void transform(TransformOutputs outputs) {
1128+ File input = inputArtifact.get().asFile
1129+ File output = outputs.file(input.name)
1130+ output.bytes = input.bytes
1131+ }
1132+ }
1133+ """.stripIndent()
1134+
1135+ file("app/src/main/java/com/company/Main.java") << """
1136+ package com.company;
1137+
1138+ public class Main {
1139+ public static void main(String[] args) {
1140+ Utils.foo();
1141+ }
1142+ }
1143+ """.stripIndent()
1144+
1145+ when:
1146+ runWithSuccess(":app:shadowJar")
1147+
1148+ then:
1149+ File outputJar = getFile("app/build/libs/app-all.jar")
1150+ outputJar.exists()
1151+ contains(outputJar, [
1152+ "com/company/Main.class",
1153+ "com/company/Utils.class",
1154+ "META-INF/MANIFEST.MF"
1155+ ])
1156+ }
10571157}
0 commit comments