-
-
Notifications
You must be signed in to change notification settings - Fork 426
Document how to make a shadowed JAR the default output of a project #1941
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -192,6 +192,138 @@ class JavaPluginsTest : BasePluginTest() { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| @Issue("https://github.com/GradleUp/shadow/issues/1893") | ||||||
| @Test | ||||||
| fun consumeShadowedProjectViaApiElementsAndRuntimeElements() { | ||||||
| settingsScript.appendText( | ||||||
| """ | ||||||
|
Goooler marked this conversation as resolved.
|
||||||
| include 'client', 'server' | ||||||
| """ | ||||||
| .trimIndent() | ||||||
| ) | ||||||
| projectScript.writeText("") | ||||||
|
|
||||||
| path("client/src/main/java/client/Client.java") | ||||||
| .writeText( | ||||||
| """ | ||||||
| package client; | ||||||
| public class Client {} | ||||||
| """ | ||||||
| .trimIndent() | ||||||
| ) | ||||||
| path("client/build.gradle") | ||||||
| .writeText( | ||||||
| """ | ||||||
| ${getDefaultProjectBuildScript("java-library")} | ||||||
|
Comment on lines
+216
to
+217
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: alignment seems off.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is formatted by ktfmt. We can do nothing.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, maybe it's ktfmt opinionated style rules that don't follow the "standard" kotlin. I know it's possible to choose the official kotlin ones, as these are not the default.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we require an indent size of two, we have to accept the Google style. To be honest, I prefer ktlint.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I just saw, the project is using google Lines 54 to 55 in 6a52076
FYI, the standard kotlin style is settable via
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting! Thanks for the precision.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be addressed by diffplug/spotless#2872.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool thanks |
||||||
| dependencies { | ||||||
| api 'junit:junit:3.8.2' | ||||||
| } | ||||||
| $shadowJarTask { | ||||||
| relocate 'junit.framework', 'client.junit.framework' | ||||||
| } | ||||||
| configurations { | ||||||
| apiElements { | ||||||
| outgoing.artifacts.clear() | ||||||
| outgoing.variants.clear() | ||||||
| outgoing.artifact($shadowJarTask) | ||||||
| } | ||||||
| runtimeElements { | ||||||
| outgoing.artifacts.clear() | ||||||
| outgoing.variants.clear() | ||||||
| outgoing.artifact($shadowJarTask) | ||||||
| } | ||||||
| } | ||||||
| """ | ||||||
| .trimIndent() + lineSeparator | ||||||
| ) | ||||||
|
|
||||||
| path("server/src/main/java/server/Server.java") | ||||||
| .writeText( | ||||||
| """ | ||||||
| package server; | ||||||
| import client.Client; | ||||||
| import client.junit.framework.Test; | ||||||
| public class Server {} | ||||||
| """ | ||||||
| .trimIndent() | ||||||
| ) | ||||||
| path("server/build.gradle") | ||||||
| .writeText( | ||||||
| """ | ||||||
| ${getDefaultProjectBuildScript("java", applyShadowPlugin = false)} | ||||||
| dependencies { | ||||||
| // No `configuration: "shadow"` needed! | ||||||
| implementation project(':client') | ||||||
| } | ||||||
| """ | ||||||
| .trimIndent() + lineSeparator | ||||||
| ) | ||||||
|
|
||||||
| // Running server:jar to ensure it compiles against the shadowed client | ||||||
| runWithSuccess(":server:jar") | ||||||
|
|
||||||
| // The fact that server compiled successfully against `client.junit.framework.Test` | ||||||
| // means it consumed the shadowed artifact during compilation. | ||||||
| assertThat(jarPath("server/build/libs/server-1.0.jar")).useAll { | ||||||
| containsAtLeast("server/Server.class") | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| @Issue("https://github.com/GradleUp/shadow/issues/1893") | ||||||
| @Test | ||||||
| fun excludeRulesPreventBundledDepsOnConsumerClasspath() { | ||||||
| settingsScript.appendText("include 'foo', 'consumer'$lineSeparator") | ||||||
| projectScript.writeText("") | ||||||
|
|
||||||
| path("foo/build.gradle") | ||||||
| .writeText( | ||||||
| """ | ||||||
| ${getDefaultProjectBuildScript("java-library")} | ||||||
| dependencies { | ||||||
| implementation 'my:a:1.0' | ||||||
| } | ||||||
| configurations { | ||||||
| named('apiElements') { | ||||||
| outgoing.artifacts.clear() | ||||||
| outgoing.variants.clear() | ||||||
| outgoing.artifact(tasks.named('shadowJar')) | ||||||
| exclude(group: 'my', module: 'a') | ||||||
| } | ||||||
| named('runtimeElements') { | ||||||
| outgoing.artifacts.clear() | ||||||
| outgoing.variants.clear() | ||||||
| outgoing.artifact(tasks.named('shadowJar')) | ||||||
| exclude(group: 'my', module: 'a') | ||||||
| } | ||||||
| } | ||||||
| """ | ||||||
| .trimIndent() + lineSeparator | ||||||
| ) | ||||||
|
|
||||||
| path("consumer/build.gradle") | ||||||
| .writeText( | ||||||
| """ | ||||||
| ${getDefaultProjectBuildScript("java", applyShadowPlugin = false)} | ||||||
| dependencies { | ||||||
| implementation project(':foo') | ||||||
| } | ||||||
| tasks.register('printClasspathFiles') { | ||||||
| def cp = configurations.runtimeClasspath | ||||||
| doLast { | ||||||
| cp.files.each { logger.lifecycle(it.name) } | ||||||
| } | ||||||
| } | ||||||
| """ | ||||||
| .trimIndent() + lineSeparator | ||||||
| ) | ||||||
|
|
||||||
| val result = runWithSuccess(":consumer:printClasspathFiles") | ||||||
| assertThat(result.output).all { | ||||||
| contains("foo-1.0-all.jar") | ||||||
| doesNotContain("a-1.0.jar") | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| @Issue("https://github.com/GradleUp/shadow/issues/1606") | ||||||
| @Test | ||||||
| fun shadowExposedCustomSourceSetOutput() { | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.