Skip to content

Test that string consts are relocated by default #1405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 17, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import assertk.assertions.isInstanceOf
import assertk.assertions.isNotEmpty
import assertk.fail
import com.github.jengelman.gradle.plugins.shadow.ShadowJavaPlugin.Companion.SHADOW_JAR_TASK_NAME
import com.github.jengelman.gradle.plugins.shadow.internal.mainClassAttributeKey
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowCopyAction.Companion.CONSTANT_TIME_FOR_ZIP_ENTRIES
import com.github.jengelman.gradle.plugins.shadow.util.Issue
import com.github.jengelman.gradle.plugins.shadow.util.containsOnly
import com.github.jengelman.gradle.plugins.shadow.util.runProcess
import java.net.URLClassLoader
import kotlin.io.path.appendText
import kotlin.io.path.writeText
Expand Down Expand Up @@ -581,6 +583,37 @@ class RelocationTest : BasePluginTest() {
}
}

@Test
fun relocateStringConstantsByDefault() {
writeClass {
"""
package my;
public class Main {
public static void main(String[] args) {
System.out.println("junit.framework.Test");
}
}
""".trimIndent()
}
projectScriptPath.appendText(
"""
$shadowJar {
manifest {
attributes '$mainClassAttributeKey': 'my.Main'
}
relocate('junit', 'foo.junit')
}
""".trimIndent(),
)

run(shadowJarTask)
val result = runProcess("java", "-jar", outputShadowJar.use { it.toString() })

assertThat(result).contains(
"foo.junit.framework.Test",
)
}

private companion object {
@JvmStatic
fun prefixProvider() = listOf(
Expand Down