Don't apply shadowJar directly

For fix project dependencies
This commit is contained in:
Karlatemp 2021-12-22 23:17:08 +08:00
parent 53883e885c
commit 45e3f58017
No known key found for this signature in database
GPG Key ID: 21FBDDF664FF06F8

View File

@ -12,13 +12,13 @@
"RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS" "RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS"
) )
import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import keys.SecretKeys import keys.SecretKeys
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.publish.maven.MavenPublication import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.bundling.Jar import org.gradle.api.tasks.bundling.Jar
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.get import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.getByName
import org.gradle.kotlin.dsl.register import org.gradle.kotlin.dsl.register
fun Project.configureRemoteRepos() { fun Project.configureRemoteRepos() {
@ -77,13 +77,22 @@ inline fun Project.configurePublishing(
setupGpg: Boolean = true, setupGpg: Boolean = true,
) { ) {
configureRemoteRepos() configureRemoteRepos()
apply<ShadowPlugin>()
val sourcesJar = if (!addProjectComponents) null else tasks.maybeCreate("sourcesJar", Jar::class.java).apply { val shadowJar = if (!addProjectComponents) null else tasks.register<ShadowJar>("shadowJar") {
archiveClassifier.set("all")
manifest.inheritFrom(tasks.getByName<Jar>("jar").manifest)
from(project.sourceSets["main"].output)
configurations = mutableListOf(
project.configurations.findByName("runtimeClasspath") ?: project.configurations["runtime"]
)
exclude("META-INF/INDEX.LIST", "META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA", "module-info.class")
}
val sourcesJar = if (!addProjectComponents) null else tasks.register<Jar>("sourcesJar") {
archiveClassifier.set("sources") archiveClassifier.set("sources")
from(sourceSets["main"].allSource) from(sourceSets["main"].allSource)
} }
val stubJavadoc = if (!addProjectComponents) null else tasks.register("javadocJar", Jar::class) { val stubJavadoc = if (!addProjectComponents) null else tasks.register<Jar>("javadocJar") {
@Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS") @Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
archiveClassifier.set("javadoc") archiveClassifier.set("javadoc")
} }
@ -104,6 +113,7 @@ inline fun Project.configurePublishing(
sourcesJar?.let { artifact(it) } sourcesJar?.let { artifact(it) }
stubJavadoc?.get()?.let { artifact(it) } stubJavadoc?.get()?.let { artifact(it) }
shadowJar?.get()?.let { artifact(it) }
} }
} }
if (setupGpg) { if (setupGpg) {