Map optional dependencies to Maven

This commit is contained in:
Rob Winch 2021-05-17 20:44:12 -05:00
parent 5b74484d3d
commit 7dc34ccef7
1 changed files with 12 additions and 0 deletions

View File

@ -1,8 +1,11 @@
package org.springframework.gradle.maven;
import io.spring.gradle.propdeps.PropDepsPlugin;
import org.gradle.api.Action;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.component.AdhocComponentWithVariants;
import org.gradle.api.plugins.JavaBasePlugin;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.publish.PublishingExtension;
@ -15,6 +18,8 @@ import org.gradle.api.publish.maven.MavenPomScm;
import org.gradle.api.publish.maven.MavenPublication;
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin;
import java.util.function.Consumer;
public class MavenPublishingConventionsPlugin implements Plugin<Project> {
@Override
public void apply(Project project) {
@ -27,6 +32,13 @@ public class MavenPublishingConventionsPlugin implements Plugin<Project> {
MavenPublishingConventionsPlugin.this.customizeJavaPlugin(project);
}
});
project.getPlugins().withType(PropDepsPlugin.class).forEach(new Consumer<PropDepsPlugin>() {
@Override
public void accept(PropDepsPlugin plugin) {
AdhocComponentWithVariants component = (AdhocComponentWithVariants) project.getComponents().findByName("java");
component.addVariantsFromConfiguration(project.getConfigurations().getByName("optional"), (details) -> details.mapToOptional());
}
});
}
private void customizePom(MavenPom pom, Project project) {