[Build] Do not use project at execution time in jar tasks
#KT-44611 In Progress
This commit is contained in:
@@ -12,6 +12,7 @@ import org.gradle.api.attributes.Attribute
|
|||||||
import org.gradle.api.attributes.LibraryElements
|
import org.gradle.api.attributes.LibraryElements
|
||||||
import org.gradle.api.attributes.java.TargetJvmEnvironment
|
import org.gradle.api.attributes.java.TargetJvmEnvironment
|
||||||
import org.gradle.api.attributes.plugin.GradlePluginApiVersion
|
import org.gradle.api.attributes.plugin.GradlePluginApiVersion
|
||||||
|
import org.gradle.api.file.FileCollection
|
||||||
import org.gradle.api.plugins.JavaLibraryPlugin
|
import org.gradle.api.plugins.JavaLibraryPlugin
|
||||||
import org.gradle.api.plugins.JavaPluginExtension
|
import org.gradle.api.plugins.JavaPluginExtension
|
||||||
import org.gradle.api.publish.PublishingExtension
|
import org.gradle.api.publish.PublishingExtension
|
||||||
@@ -480,8 +481,8 @@ fun Project.publishShadowedJar(
|
|||||||
|
|
||||||
// When Gradle traverses the inputs, reject the shaded compiler JAR,
|
// When Gradle traverses the inputs, reject the shaded compiler JAR,
|
||||||
// which leads to the content of that JAR being excluded as well:
|
// which leads to the content of that JAR being excluded as well:
|
||||||
val compilerDummyJarFile = project.provider { project.configurations.getByName("compilerDummyJar").singleFile }
|
val compilerDummyJarConfiguration: FileCollection = project.configurations.getByName("compilerDummyJar")
|
||||||
exclude { it.file == compilerDummyJarFile.get() }
|
exclude { it.file == compilerDummyJarConfiguration.singleFile }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Removing artifact produced by Jar task
|
// Removing artifact produced by Jar task
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import org.gradle.api.artifacts.component.ProjectComponentIdentifier
|
|||||||
import org.gradle.api.attributes.LibraryElements
|
import org.gradle.api.attributes.LibraryElements
|
||||||
import org.gradle.api.attributes.Usage
|
import org.gradle.api.attributes.Usage
|
||||||
import org.gradle.api.component.AdhocComponentWithVariants
|
import org.gradle.api.component.AdhocComponentWithVariants
|
||||||
|
import org.gradle.api.file.ArchiveOperations
|
||||||
import org.gradle.api.file.DuplicatesStrategy
|
import org.gradle.api.file.DuplicatesStrategy
|
||||||
import org.gradle.api.plugins.BasePluginExtension
|
import org.gradle.api.plugins.BasePluginExtension
|
||||||
import org.gradle.api.plugins.JavaPlugin
|
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.publish.tasks.GenerateModuleMetadata
|
||||||
import org.gradle.api.tasks.TaskProvider
|
import org.gradle.api.tasks.TaskProvider
|
||||||
import org.gradle.api.tasks.javadoc.Javadoc
|
import org.gradle.api.tasks.javadoc.Javadoc
|
||||||
|
import org.gradle.configurationcache.extensions.serviceOf
|
||||||
import org.gradle.jvm.tasks.Jar
|
import org.gradle.jvm.tasks.Jar
|
||||||
import org.gradle.kotlin.dsl.*
|
import org.gradle.kotlin.dsl.*
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetContainer
|
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetContainer
|
||||||
@@ -70,10 +72,11 @@ fun Project.noDefaultJar() {
|
|||||||
fun Jar.addEmbeddedRuntime() {
|
fun Jar.addEmbeddedRuntime() {
|
||||||
project.configurations.findByName("embedded")?.let { embedded ->
|
project.configurations.findByName("embedded")?.let { embedded ->
|
||||||
dependsOn(embedded)
|
dependsOn(embedded)
|
||||||
|
val archiveOperations = project.serviceOf<ArchiveOperations>()
|
||||||
from {
|
from {
|
||||||
embedded.map {
|
embedded.map {
|
||||||
if (it.extension.equals("jar", ignoreCase = true)) {
|
if (it.extension.equals("jar", ignoreCase = true)) {
|
||||||
project.zipTree(it)
|
archiveOperations.zipTree(it)
|
||||||
} else {
|
} else {
|
||||||
it
|
it
|
||||||
}
|
}
|
||||||
@@ -144,7 +147,7 @@ fun Project.sourcesJar(body: Jar.() -> Unit = {}): TaskProvider<Jar> {
|
|||||||
|
|
||||||
fun Jar.addEmbeddedSources() {
|
fun Jar.addEmbeddedSources() {
|
||||||
project.configurations.findByName("embedded")?.let { embedded ->
|
project.configurations.findByName("embedded")?.let { embedded ->
|
||||||
from(project.provider {
|
val allSources by lazy {
|
||||||
embedded.resolvedConfiguration
|
embedded.resolvedConfiguration
|
||||||
.resolvedArtifacts
|
.resolvedArtifacts
|
||||||
.map { it.id.componentIdentifier }
|
.map { it.id.componentIdentifier }
|
||||||
@@ -152,7 +155,8 @@ fun Jar.addEmbeddedSources() {
|
|||||||
.mapNotNull {
|
.mapNotNull {
|
||||||
project.project(it.projectPath).sources()
|
project.project(it.projectPath).sources()
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
from({ allSources })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,9 +271,9 @@ fun Project.publishProjectJars(projects: List<String>, libraryDependencies: List
|
|||||||
|
|
||||||
jar.apply {
|
jar.apply {
|
||||||
dependsOn(fatJarContents)
|
dependsOn(fatJarContents)
|
||||||
|
val archiveOperations = project.serviceOf<ArchiveOperations>()
|
||||||
from {
|
from {
|
||||||
fatJarContents.map(::zipTree)
|
fatJarContents.map(archiveOperations::zipTree)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,9 +305,9 @@ fun Project.publishTestJar(projects: List<String>, excludedPaths: List<String>)
|
|||||||
|
|
||||||
jar.apply {
|
jar.apply {
|
||||||
dependsOn(fatJarContents)
|
dependsOn(fatJarContents)
|
||||||
|
val archiveOperations = project.serviceOf<ArchiveOperations>()
|
||||||
from {
|
from {
|
||||||
fatJarContents.map(::zipTree)
|
fatJarContents.map(archiveOperations::zipTree)
|
||||||
}
|
}
|
||||||
|
|
||||||
exclude(excludedPaths)
|
exclude(excludedPaths)
|
||||||
|
|||||||
Reference in New Issue
Block a user