Skip to content
Draft
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
23 changes: 23 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.gradle.api.plugins.JavaPlugin.SOURCES_ELEMENTS_CONFIGURATION_NAME
import org.gradle.plugin.compatibility.compatibility
import org.jetbrains.kotlin.gradle.dsl.JvmDefaultMode
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.dsl.abi.ExperimentalAbiValidation

Expand Down Expand Up @@ -45,6 +46,8 @@ kotlin {
}
}

addMultiReleaseSourceSet(24)

lint {
baseline = file("gradle/lint-baseline.xml")
ignoreTestFixturesSources = true
Expand Down Expand Up @@ -222,6 +225,8 @@ kotlin.target.compilations {
}
}

tasks.jar { manifest.attributes("Multi-Release" to true) }

tasks.pluginUnderTestMetadata { pluginClasspath.from(testPluginClasspath) }

tasks.check { dependsOn(tasks.withType<Test>()) }
Expand All @@ -236,3 +241,21 @@ tasks.clean {
rootDir.resolve("site"),
)
}

fun addMultiReleaseSourceSet(version: Int) {
kotlin.target.compilations.create("java${version}") {
associateWith(kotlin.target.compilations.getByName("main"))
compileTaskProvider {
compilerOptions {
this@compilerOptions as KotlinJvmCompilerOptions
jvmTarget = JvmTarget.fromTarget(version.toString())
freeCompilerArgs.add("-Xjdk-release=$version")
}
}
compileJavaTaskProvider { options.release = version }

tasks.jar { from(output.allOutputs) { into("META-INF/versions/$version") } }

tasks.withType<Test>().configureEach { inputs.files(output.allOutputs) }
}
}
5 changes: 5 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
# https://kotlinlang.org/docs/gradle-configure-project.html#dependency-on-the-standard-library
kotlin.stdlib.default.dependency=false

# Keep associated Kotlin compilations from depending on archive tasks (e.g., jar), which can create circular task graphs in multi-release setups.
# https://kotlinlang.org/docs/gradle-configure-project.html#disable-use-of-artifact-in-compilation-task
# https://kotlinlang.org/docs/whatsnew2020.html#added-task-dependency-for-rare-cases-when-the-compile-task-lacks-one-on-an-artifact
kotlin.build.archivesTaskOutputAsFriendModule=false

org.gradle.caching=true
org.gradle.configuration-cache=true
org.gradle.configuration-cache.parallel=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,45 @@ class RelocationTest : BasePluginTest() {
}
}

@Test
fun relocateAnnotationStringConstants() {
writeClass {
"""
package my;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
@interface MyAnnotation {
String value();
}
@MyAnnotation("foo.Bar")
public class Main {
public static void main(String[] args) {
MyAnnotation ann = Main.class.getAnnotation(MyAnnotation.class);
System.out.println(ann.value());
}
}
"""
.trimIndent()
}
projectScript.appendText(
"""
$shadowJarTask {
manifest {
attributes '$mainClassAttributeKey': 'my.Main'
}
relocate('foo', 'shadow.foo')
}
"""
.trimIndent()
)

runWithSuccess(shadowJarPath)
val result = runProcess("java", "-jar", outputShadowedJar.use { it.toString() })

assertThat(result).contains("shadow.foo.Bar")
}

@Issue("https://github.com/GradleUp/shadow/issues/1403")
@Test
fun relocateMultiClassSignatureStringConstants() {
Expand Down
Loading
Loading