Skip to content

Incompatible with the shadow plugin/shadowDist #94

@tajobe

Description

@tajobe

The Gradle shadow plugin has the ability to create an equivalent distribution but using the shadowed dependencies: https://imperceptiblethoughts.com/shadow/application-plugin/#distributing-the-shadow-jar

This plugin seems to set the javaagent path specifically for the ApplicationPlugin's task, not any/all CreateStartScripts type tasks. It might be useful to add the same injection of the javaagent to the ShadowApplicationPlugin.SHADOW_SCRIPTS_TASK_NAME task so it can be used in conjunction with shadow.


Working around this by basically recreating what the plugin does:

distributions.named("shadow") {
    contents.from(configurations.javaagent) { into("agent-libs") }
}

tasks.named<CreateStartScripts>(ShadowApplicationPlugin.SHADOW_SCRIPTS_TASK_NAME) {
    inputs.files(configurations.javaagent)
    defaultJvmOpts = listOf("-javaagent:COM_RYANDENS_JAVAAGENTS_PLACEHOLDER.jar").plus(defaultJvmArgs)
    unixStartScriptGenerator = JavaagentAwareStartScriptGenerator(configurations.javaagent.map { it.files })
}

Edit: the workaround is a bit more complicated as the script generated using the above isn't usable...instead I'm manually mapping the javaagent files to jvm opts and working around gradle/gradle#19795 with a pattern/replace. It's a bit ugly...

tasks.named<CreateStartScripts>(ShadowApplicationPlugin.SHADOW_SCRIPTS_TASK_NAME) {
    defaultJvmOpts = configurations.javaagent.get().files.map { jar ->
        "-javaagent:\$\\{APP_HOME\\}/agent-libs/${jar.name}"
    }.plus(defaultJvmArgs)

    // FIXME - Replace env var template in `DEFAULT_JVM_OPTS`
    //  Workaround for https://github.com/gradle/gradle/issues/19795
    doLast {
        val envVarRegex = "\\\\\\$\\\\\\\\\\{(\\w+)\\\\\\\\\\}".toRegex()
        val startScript = outputs.files.single().listFiles { file -> file.name == rootProject.name }!!.single()
        val contents = startScript.readLines().joinToString("\n") { line ->
            if (line.startsWith("DEFAULT_JVM_OPTS")) line.replace(envVarRegex, "\\$$1") else line
        }
        startScript.writeText(contents)
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions