Skip to content

Commit

Permalink
add support for newer shadow gradle plugin id: com.gradleup.shadow
Browse files Browse the repository at this point in the history
  • Loading branch information
rpalcolea committed Aug 22, 2024
1 parent d849629 commit 30c7d70
Show file tree
Hide file tree
Showing 8 changed files with 985 additions and 867 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,42 @@ class IvyShadowPublishPlugin implements Plugin<Project> {
void apply(Project project) {
project.afterEvaluate {
project.plugins.withId('com.github.johnrengelman.shadow') {
Task shadowJarTask = project.tasks.findByName('shadowJar')
boolean jarTaskEnabled = project.tasks.findByName('jar').enabled
if (!jarTaskEnabled) {
ShadowJarPublicationConfigurer.configureForJarDisabled(project)
} else {
//presence of this configurations means that shadow jar plugin is version 6.+
//all the configuration below is done for us there and we can skip
if (project.configurations.findByName("shadowRuntimeElements") == null) {
PublishingExtension publishing = project.extensions.getByType(PublishingExtension)
publishing.publications(new Action<PublicationContainer>() {
@Override
void execute(PublicationContainer publications) {
if (shadowJarTask) {
publications.withType(IvyPublication) { IvyPublication publication ->
publication.configurations {
'shadowRuntimeElements' {}
}
publication.artifact(shadowJarTask, new Action<IvyArtifact>() {
@Override
void execute(IvyArtifact ivyArtifact) {
ivyArtifact.setConf('shadowRuntimeElements')
}
})
}
configureProject(project)
}
project.plugins.withId('com.gradleup.shadow') {
configureProject(project)
}
}
}

private void configureProject(Project project) {
Task shadowJarTask = project.tasks.findByName('shadowJar')
boolean jarTaskEnabled = project.tasks.findByName('jar').enabled
if (!jarTaskEnabled) {
ShadowJarPublicationConfigurer.configureForJarDisabled(project)
} else {
//presence of this configurations means that shadow jar plugin is version 6.+
//all the configuration below is done for us there and we can skip
if (project.configurations.findByName("shadowRuntimeElements") == null) {
PublishingExtension publishing = project.extensions.getByType(PublishingExtension)
publishing.publications(new Action<PublicationContainer>() {
@Override
void execute(PublicationContainer publications) {
if (shadowJarTask) {
publications.withType(IvyPublication) { IvyPublication publication ->
publication.configurations {
'shadowRuntimeElements' {}
}
publication.artifact(shadowJarTask, new Action<IvyArtifact>() {
@Override
void execute(IvyArtifact ivyArtifact) {
ivyArtifact.setConf('shadowRuntimeElements')
}
})
}
})
}
}
}
})
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,34 @@ class MavenShadowPublishPlugin implements Plugin<Project> {
void apply(Project project) {
project.afterEvaluate {
project.plugins.withId('com.github.johnrengelman.shadow') {
Task shadowJarTask = project.tasks.findByName('shadowJar')
boolean jarTaskEnabled = project.tasks.findByName('jar').enabled
if (!jarTaskEnabled) {
ShadowJarPublicationConfigurer.configureForJarDisabled(project)
} else {
//presence of this configurations means that shadow jar plugin is version 6.+
//all the configuration below is done for us there and we can skip
if (project.configurations.findByName("shadowRuntimeElements") == null) {
PublishingExtension publishing = project.extensions.getByType(PublishingExtension)
publishing.publications(new Action<PublicationContainer>() {
@Override
void execute(PublicationContainer publications) {
if (shadowJarTask) {
publications.withType(MavenPublication) { MavenPublication publication ->
publication.artifact(shadowJarTask)
}
}
configureProject(project)
}
project.plugins.withId('com.gradleup.shadow') {
configureProject(project)
}
}
}

private void configureProject(Project project) {
Task shadowJarTask = project.tasks.findByName('shadowJar')
boolean jarTaskEnabled = project.tasks.findByName('jar').enabled
if (!jarTaskEnabled) {
ShadowJarPublicationConfigurer.configureForJarDisabled(project)
} else {
//presence of this configurations means that shadow jar plugin is version 6.+
//all the configuration below is done for us there and we can skip
if (project.configurations.findByName("shadowRuntimeElements") == null) {
PublishingExtension publishing = project.extensions.getByType(PublishingExtension)
publishing.publications(new Action<PublicationContainer>() {
@Override
void execute(PublicationContainer publications) {
if (shadowJarTask) {
publications.withType(MavenPublication) { MavenPublication publication ->
publication.artifact(shadowJarTask)
}
})
}
}
}
})
}
}
}
Expand Down
Loading

0 comments on commit 30c7d70

Please sign in to comment.