Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -216,79 +216,6 @@ abstract class BasePluginTest {
)
}

fun writeApiLibAndImplModules() {
settingsScriptPath.appendText(
"""
include 'api', 'lib', 'impl'
""".trimIndent() + System.lineSeparator(),
)
projectScriptPath.writeText("")

path("lib/src/main/java/lib/LibEntity.java").writeText(
"""
package lib;
public interface LibEntity {}
""".trimIndent(),
)
path("lib/src/main/java/lib/UnusedLibEntity.java").writeText(
"""
package lib;
public class UnusedLibEntity implements LibEntity {}
""".trimIndent(),
)
path("lib/build.gradle").writeText(
"""
plugins {
id 'java'
}
""".trimIndent() + System.lineSeparator(),
)

path("api/src/main/java/api/Entity.java").writeText(
"""
package api;
public interface Entity {}
""".trimIndent(),
)
path("api/src/main/java/api/UnusedEntity.java").writeText(
"""
package api;
import lib.LibEntity;
public class UnusedEntity implements LibEntity {}
""".trimIndent(),
)
path("api/build.gradle").writeText(
"""
plugins {
id 'java'
}
dependencies {
implementation 'junit:junit:3.8.2'
implementation project(':lib')
}
""".trimIndent() + System.lineSeparator(),
)

path("impl/src/main/java/impl/SimpleEntity.java").writeText(
"""
package impl;
import api.Entity;
public class SimpleEntity implements Entity {}
""".trimIndent(),
)
path("impl/build.gradle").writeText(
"""
${getDefaultProjectBuildScript("java-library")}
dependencies {
api project(':api')
}
$shadowJar {
minimize()
}
""".trimIndent() + System.lineSeparator(),
)
}

fun writeGradlePluginModule(legacy: Boolean) {
val pluginId = "my.plugin"
val pluginClass = "my.plugin.MyPlugin"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,202 +150,6 @@ class JavaPluginTest : BasePluginTest() {
}
}

/**
* 'Server' depends on 'Client'. 'junit' is independent.
* The minimize shall remove 'junit'.
*/
@Test
fun minimizeByKeepingOnlyTransitiveDependencies() {
writeClientAndServerModules(
serverShadowBlock = """
minimize()
""".trimIndent(),
)
path("server/src/main/java/server/Server.java").writeText(
"""
package server;
import client.Client;
public class Server {
// This is to make sure that 'Client' is not removed.
private final String client = Client.class.getName();
}
""".trimIndent(),
)

run(serverShadowJarTask)

assertThat(outputServerShadowJar).useAll {
containsEntries(
"client/Client.class",
"server/Server.class",
)
doesNotContainEntries(
"junit/framework/Test.class",
)
}
}

/**
* 'Client', 'Server' and 'junit' are independent.
* 'junit' is excluded from the minimize step.
* The minimize step shall remove 'Client' but not 'junit'.
*/
@Test
fun excludeDependencyFromMinimize() {
writeClientAndServerModules(
serverShadowBlock = """
minimize {
exclude(dependency('junit:junit:.*'))
}
""".trimIndent(),
)

run(serverShadowJarTask)

assertThat(outputServerShadowJar).useAll {
containsEntries(
"server/Server.class",
"junit/framework/Test.class",
)
doesNotContainEntries(
"client/Client.class",
)
}
}

/**
* 'Client', 'Server' and 'junit' are independent.
* Unused classes of 'client' and theirs dependencies shouldn't be removed.
*/
@Test
fun excludeProjectFromMinimize() {
writeClientAndServerModules(
serverShadowBlock = """
minimize {
exclude(project(':client'))
}
""".trimIndent(),
)

run(serverShadowJarTask)

assertThat(outputServerShadowJar).useAll {
containsEntries(
"client/Client.class",
"server/Server.class",
)
}
}

/**
* 'Client', 'Server' and 'junit' are independent.
* Unused classes of 'client' and theirs dependencies shouldn't be removed.
*/
@Test
fun excludeProjectFromMinimizeShallNotExcludeTransitiveDependenciesThatAreUsedInSubproject() {
writeClientAndServerModules(
serverShadowBlock = """
minimize {
exclude(project(':client'))
}
""".trimIndent(),
)
path("client/src/main/java/client/Client.java").writeText(
"""
package client;
import junit.framework.TestCase;
public class Client extends TestCase {
public static void main(String[] args) {}
}
""".trimIndent(),
)

run(serverShadowJarTask)

assertThat(outputServerShadowJar).useAll {
containsEntries(
"client/Client.class",
"server/Server.class",
"junit/framework/TestCase.class",
)
}

path("client/src/main/java/client/Client.java").writeText(
"""
package client;
public class Client {}
""".trimIndent(),
)
run(serverShadowJarTask)

assertThat(outputServerShadowJar).useAll {
containsEntries(
"client/Client.class",
"server/Server.class",
"junit/framework/TestCase.class",
)
}
}

/**
* 'api' used as api for 'impl', and depended on 'lib'. 'junit' is independent.
* The minimize step shall remove 'junit', but not 'api'.
* Unused classes of 'api' and theirs dependencies also shouldn't be removed.
*/
@Test
fun useMinimizeWithDependenciesWithApiScope() {
writeApiLibAndImplModules()

run(":impl:$SHADOW_JAR_TASK_NAME")

assertThat(jarPath("impl/build/libs/impl-all.jar")).useAll {
containsEntries(
"impl/SimpleEntity.class",
"api/Entity.class",
"api/UnusedEntity.class",
"lib/LibEntity.class",
)
doesNotContainEntries(
"junit/framework/Test.class",
"lib/UnusedLibEntity.class",
)
}
}

/**
* 'api' used as api for 'impl', and 'lib' used as api for 'api'.
* Unused classes of 'api' and 'lib' shouldn't be removed.
*/
@Test
fun useMinimizeWithTransitiveDependenciesWithApiScope() {
writeApiLibAndImplModules()
path("api/build.gradle").writeText(
"""
plugins {
id 'java-library'
}
dependencies {
api project(':lib')
}
""".trimIndent(),
)

run(":impl:$SHADOW_JAR_TASK_NAME")

assertThat(jarPath("impl/build/libs/impl-all.jar")).useAll {
containsEntries(
"impl/SimpleEntity.class",
"api/Entity.class",
"api/UnusedEntity.class",
"lib/LibEntity.class",
"lib/UnusedLibEntity.class",
)
doesNotContainEntries(
"junit/framework/Test.class",
)
}
}

@Test
fun dependOnProjectShadowJar() {
writeShadowedClientAndServerModules()
Expand Down
Loading