Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
Support CC in ShadowExtension.component
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler committed Mar 2, 2023
1 parent 85b9e06 commit 6bbc401
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/docs/publishing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ apply plugin: 'com.github.johnrengelman.shadow'
publishing {
publications {
shadow(MavenPublication) { publication ->
project.shadow.component(publication)
project.shadow.component(project, publication)
}
}
repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ShadowBasePlugin implements Plugin<Project> {
if (GradleVersion.current() < GradleVersion.version("8.0")) {
throw new GradleException("This version of Shadow supports Gradle 8.0+ only. Please upgrade.")
}
project.extensions.create(EXTENSION_NAME, ShadowExtension, project)
project.extensions.create(EXTENSION_NAME, ShadowExtension)
createShadowConfiguration(project)

project.tasks.register(KnowsTask.NAME, KnowsTask) { knows ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,50 @@ package com.github.jengelman.gradle.plugins.shadow
import org.gradle.api.Project
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.artifacts.SelfResolvingDependency
import org.gradle.api.file.CopySpec
import org.gradle.api.publish.maven.MavenPom
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.util.GradleVersion

class ShadowExtension {

CopySpec applicationDistribution
Project project

ShadowExtension(Project project) {
this.project = project
applicationDistribution = project.copySpec {}
}

void component(MavenPublication publication) {
void component(Project project, MavenPublication publication) {

if (GradleVersion.current() >= GradleVersion.version("6.6")) {
publication.artifact(project.tasks.named("shadowJar"))
} else {
publication.artifact(project.tasks.shadowJar)
}

final def allDependencies = project.provider {
project.configurations.shadow.allDependencies.collect {
if ((it instanceof ProjectDependency) || ! (it instanceof SelfResolvingDependency)) {
new Dep(it.group, it.name, it.version)
}
}
}
publication.pom { MavenPom pom ->
pom.withXml { xml ->
def dependenciesNode = xml.asNode().get('dependencies') ?: xml.asNode().appendNode('dependencies')
project.configurations.shadow.allDependencies.each {
if ((it instanceof ProjectDependency) || ! (it instanceof SelfResolvingDependency)) {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
dependencyNode.appendNode('scope', 'runtime')
}
allDependencies.get().each {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
dependencyNode.appendNode('scope', 'runtime')
}
}
}
}

private class Dep {
String group
String name
String version

Dep(String group, String name, String version) {
this.group = group
this.name = name
this.version = version
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class PublishingSpec extends PluginSpecification {
publishing {
publications {
shadow(MavenPublication) { publication ->
project.shadow.component(publication)
project.shadow.component(project, publication)
artifactId = 'maven-all'
}
}
Expand All @@ -52,10 +52,6 @@ class PublishingSpec extends PluginSpecification {
}
}
}
tasks.withType(org.gradle.api.publish.maven.tasks.GenerateMavenPom).configureEach {
notCompatibleWithConfigurationCache('https://github.com/gradle/gradle/issues/21926')
}
""".stripIndent()

when:
Expand Down Expand Up @@ -148,15 +144,11 @@ class PublishingSpec extends PluginSpecification {
publishing {
publications {
shadow(MavenPublication) { publication ->
project.shadow.component(publication)
project.shadow.component(project, publication)
artifactId = 'maven-all'
}
}
}
tasks.withType(org.gradle.api.publish.maven.tasks.GenerateMavenPom).configureEach {
notCompatibleWithConfigurationCache('https://github.com/gradle/gradle/issues/21926')
}
""".stripMargin()

when:
Expand Down

0 comments on commit 6bbc401

Please sign in to comment.