@@ -192,6 +192,138 @@ class JavaPluginsTest : BasePluginTest() {
192192 }
193193 }
194194
195+ @Issue(" https://github.com/GradleUp/shadow/issues/1893" )
196+ @Test
197+ fun consumeShadowedProjectViaApiElementsAndRuntimeElements () {
198+ settingsScript.appendText(
199+ """
200+ include 'client', 'server'
201+ """
202+ .trimIndent()
203+ )
204+ projectScript.writeText(" " )
205+
206+ path(" client/src/main/java/client/Client.java" )
207+ .writeText(
208+ """
209+ package client;
210+ public class Client {}
211+ """
212+ .trimIndent()
213+ )
214+ path(" client/build.gradle" )
215+ .writeText(
216+ """
217+ ${getDefaultProjectBuildScript(" java-library" )}
218+ dependencies {
219+ api 'junit:junit:3.8.2'
220+ }
221+ $shadowJarTask {
222+ relocate 'junit.framework', 'client.junit.framework'
223+ }
224+ configurations {
225+ apiElements {
226+ outgoing.artifacts.clear()
227+ outgoing.variants.clear()
228+ outgoing.artifact($shadowJarTask )
229+ }
230+ runtimeElements {
231+ outgoing.artifacts.clear()
232+ outgoing.variants.clear()
233+ outgoing.artifact($shadowJarTask )
234+ }
235+ }
236+ """
237+ .trimIndent() + lineSeparator
238+ )
239+
240+ path(" server/src/main/java/server/Server.java" )
241+ .writeText(
242+ """
243+ package server;
244+ import client.Client;
245+ import client.junit.framework.Test;
246+ public class Server {}
247+ """
248+ .trimIndent()
249+ )
250+ path(" server/build.gradle" )
251+ .writeText(
252+ """
253+ ${getDefaultProjectBuildScript(" java" , applyShadowPlugin = false )}
254+ dependencies {
255+ // No `configuration: "shadow"` needed!
256+ implementation project(':client')
257+ }
258+ """
259+ .trimIndent() + lineSeparator
260+ )
261+
262+ // Running server:jar to ensure it compiles against the shadowed client
263+ runWithSuccess(" :server:jar" )
264+
265+ // The fact that server compiled successfully against `client.junit.framework.Test`
266+ // means it consumed the shadowed artifact during compilation.
267+ assertThat(jarPath(" server/build/libs/server-1.0.jar" )).useAll {
268+ containsAtLeast(" server/Server.class" )
269+ }
270+ }
271+
272+ @Issue(" https://github.com/GradleUp/shadow/issues/1893" )
273+ @Test
274+ fun excludeRulesPreventBundledDepsOnConsumerClasspath () {
275+ settingsScript.appendText(" include 'foo', 'consumer'$lineSeparator " )
276+ projectScript.writeText(" " )
277+
278+ path(" foo/build.gradle" )
279+ .writeText(
280+ """
281+ ${getDefaultProjectBuildScript(" java-library" )}
282+ dependencies {
283+ implementation 'my:a:1.0'
284+ }
285+ configurations {
286+ named('apiElements') {
287+ outgoing.artifacts.clear()
288+ outgoing.variants.clear()
289+ outgoing.artifact(tasks.named('shadowJar'))
290+ exclude(group: 'my', module: 'a')
291+ }
292+ named('runtimeElements') {
293+ outgoing.artifacts.clear()
294+ outgoing.variants.clear()
295+ outgoing.artifact(tasks.named('shadowJar'))
296+ exclude(group: 'my', module: 'a')
297+ }
298+ }
299+ """
300+ .trimIndent() + lineSeparator
301+ )
302+
303+ path(" consumer/build.gradle" )
304+ .writeText(
305+ """
306+ ${getDefaultProjectBuildScript(" java" , applyShadowPlugin = false )}
307+ dependencies {
308+ implementation project(':foo')
309+ }
310+ tasks.register('printClasspathFiles') {
311+ def cp = configurations.runtimeClasspath
312+ doLast {
313+ cp.files.each { logger.lifecycle(it.name) }
314+ }
315+ }
316+ """
317+ .trimIndent() + lineSeparator
318+ )
319+
320+ val result = runWithSuccess(" :consumer:printClasspathFiles" )
321+ assertThat(result.output).all {
322+ contains(" foo-1.0-all.jar" )
323+ doesNotContain(" a-1.0.jar" )
324+ }
325+ }
326+
195327 @Issue(" https://github.com/GradleUp/shadow/issues/1606" )
196328 @Test
197329 fun shadowExposedCustomSourceSetOutput () {
0 commit comments