[Build] Do not use project at execution time in jar tasks

#KT-44611 In Progress
This commit is contained in:
Alexander Likhachev
2022-04-08 17:31:02 +03:00
parent 6d654a4b10
commit df55745b61
2 changed files with 14 additions and 9 deletions
+3 -2
View File
@@ -12,6 +12,7 @@ import org.gradle.api.attributes.Attribute
import org.gradle.api.attributes.LibraryElements
import org.gradle.api.attributes.java.TargetJvmEnvironment
import org.gradle.api.attributes.plugin.GradlePluginApiVersion
import org.gradle.api.file.FileCollection
import org.gradle.api.plugins.JavaLibraryPlugin
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.publish.PublishingExtension
@@ -480,8 +481,8 @@ fun Project.publishShadowedJar(
// When Gradle traverses the inputs, reject the shaded compiler JAR,
// which leads to the content of that JAR being excluded as well:
val compilerDummyJarFile = project.provider { project.configurations.getByName("compilerDummyJar").singleFile }
exclude { it.file == compilerDummyJarFile.get() }
val compilerDummyJarConfiguration: FileCollection = project.configurations.getByName("compilerDummyJar")
exclude { it.file == compilerDummyJarConfiguration.singleFile }
}
// Removing artifact produced by Jar task
+11 -7
View File
@@ -11,6 +11,7 @@ import org.gradle.api.artifacts.component.ProjectComponentIdentifier
import org.gradle.api.attributes.LibraryElements
import org.gradle.api.attributes.Usage
import org.gradle.api.component.AdhocComponentWithVariants
import org.gradle.api.file.ArchiveOperations
import org.gradle.api.file.DuplicatesStrategy
import org.gradle.api.plugins.BasePluginExtension
import org.gradle.api.plugins.JavaPlugin
@@ -22,6 +23,7 @@ import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.publish.tasks.GenerateModuleMetadata
import org.gradle.api.tasks.TaskProvider
import org.gradle.api.tasks.javadoc.Javadoc
import org.gradle.configurationcache.extensions.serviceOf
import org.gradle.jvm.tasks.Jar
import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetContainer
@@ -70,10 +72,11 @@ fun Project.noDefaultJar() {
fun Jar.addEmbeddedRuntime() {
project.configurations.findByName("embedded")?.let { embedded ->
dependsOn(embedded)
val archiveOperations = project.serviceOf<ArchiveOperations>()
from {
embedded.map {
if (it.extension.equals("jar", ignoreCase = true)) {
project.zipTree(it)
archiveOperations.zipTree(it)
} else {
it
}
@@ -144,7 +147,7 @@ fun Project.sourcesJar(body: Jar.() -> Unit = {}): TaskProvider<Jar> {
fun Jar.addEmbeddedSources() {
project.configurations.findByName("embedded")?.let { embedded ->
from(project.provider {
val allSources by lazy {
embedded.resolvedConfiguration
.resolvedArtifacts
.map { it.id.componentIdentifier }
@@ -152,7 +155,8 @@ fun Jar.addEmbeddedSources() {
.mapNotNull {
project.project(it.projectPath).sources()
}
})
}
from({ allSources })
}
}
@@ -267,9 +271,9 @@ fun Project.publishProjectJars(projects: List<String>, libraryDependencies: List
jar.apply {
dependsOn(fatJarContents)
val archiveOperations = project.serviceOf<ArchiveOperations>()
from {
fatJarContents.map(::zipTree)
fatJarContents.map(archiveOperations::zipTree)
}
}
@@ -301,9 +305,9 @@ fun Project.publishTestJar(projects: List<String>, excludedPaths: List<String>)
jar.apply {
dependsOn(fatJarContents)
val archiveOperations = project.serviceOf<ArchiveOperations>()
from {
fatJarContents.map(::zipTree)
fatJarContents.map(archiveOperations::zipTree)
}
exclude(excludedPaths)