Skip to content
Closed
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 @@ -7,6 +7,7 @@ import com.github.jengelman.gradle.plugins.shadow.internal.runtimeConfiguration
import com.github.jengelman.gradle.plugins.shadow.internal.sourceSets
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar.Companion.registerShadowJarCommon
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar.Companion.shadowJar
import java.io.File
import javax.inject.Inject
import org.gradle.api.NamedDomainObjectProvider
import org.gradle.api.Plugin
Expand Down Expand Up @@ -42,6 +43,11 @@ constructor(private val softwareComponentFactory: SoftwareComponentFactory) : Pl
registerShadowJarCommon(tasks.named("jar", Jar::class.java)) { task ->
task.from(sourceSets.named("main").map { it.output })
task.configurations.convention(provider { listOf(runtimeConfiguration) })
// Include all source sets (including test) so that test code's transitive dependency
// references are also considered "used" during minimization.
task.sourceSetsClassesDirs.convention(
sourceSets.map { it.output.classesDirs.filter(File::isDirectory) }
)
Comment on lines +46 to +50
}
artifacts.add(configurations.shadow.name, taskProvider)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.github.jengelman.gradle.plugins.shadow
import com.github.jengelman.gradle.plugins.shadow.internal.isAtLeastKgp
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar.Companion.SHADOW_JAR_TASK_NAME
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar.Companion.registerShadowJarCommon
import java.io.File
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.tasks.bundling.Jar
Expand Down Expand Up @@ -41,6 +42,13 @@ public abstract class ShadowKmpPlugin : Plugin<Project> {
.flatMap { configurations.named(it.runtimeDependencyConfigurationName) }
.map { listOf(it) }
)
// Include all compilations (including test) so that test code's transitive dependency
// references are also considered "used" during minimization.
task.sourceSetsClassesDirs.convention(
target.compilations.map { compilation ->
compilation.output.classesDirs.filter(File::isDirectory)
}
)

if (!isAtLeastKgp("1.9.0")) return@registerShadowJarCommon

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import com.github.jengelman.gradle.plugins.shadow.internal.minimizeWithR8
import com.github.jengelman.gradle.plugins.shadow.internal.multiReleaseAttributeKey
import com.github.jengelman.gradle.plugins.shadow.internal.property
import com.github.jengelman.gradle.plugins.shadow.internal.setProperty
import com.github.jengelman.gradle.plugins.shadow.internal.sourceSets
import com.github.jengelman.gradle.plugins.shadow.internal.useZip
import com.github.jengelman.gradle.plugins.shadow.relocation.CacheableRelocator
import com.github.jengelman.gradle.plugins.shadow.relocation.Relocator
Expand Down Expand Up @@ -138,17 +137,7 @@ public abstract class ShadowJar : Jar() {

@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
public open val sourceSetsClassesDirs: ConfigurableFileCollection = objectFactory.fileCollection {
_minimizeJar.map {
if (it) {
project.sourceSets.map { sourceSet ->
sourceSet.output.classesDirs.filter(File::isDirectory)
}
} else {
emptySet()
}
}
}
public open val sourceSetsClassesDirs: ConfigurableFileCollection = objectFactory.fileCollection()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right! This is a potential breaking change for users who register the task by themselves.


@get:Classpath
public open val r8Classpath: ConfigurableFileCollection = objectFactory.fileCollection {
Expand Down