Fix maven.from

This commit is contained in:
Rob Winch 2021-05-17 17:49:37 -05:00
parent c72f8dec0c
commit daf37942c5
1 changed files with 10 additions and 5 deletions

View File

@ -5,7 +5,10 @@ import org.gradle.api.Action;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.plugins.JavaPlatformPlugin;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.publish.PublishingExtension;
import org.gradle.api.publish.VariantVersionMappingStrategy;
import org.gradle.api.publish.VersionMappingStrategy;
import org.gradle.api.publish.maven.MavenPublication;
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin;
@ -14,13 +17,15 @@ public class PublishAllJavaComponentsPlugin implements Plugin<Project> {
public void apply(Project project) {
project.getPlugins().withType(MavenPublishPlugin.class).all((mavenPublish) -> {
PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class);
publishing.getPublications().create("maven", MavenPublication.class, new Action<MavenPublication>() {
publishing.getPublications().create("mavenJava", MavenPublication.class, new Action<MavenPublication>() {
@Override
public void execute(MavenPublication maven) {
project.getPlugins().withType(JavaPlatformPlugin.class)
.all((javaPlugin) -> project.getComponents()
.matching((component) -> component.getName().equals("javaPlatform"))
.all((javaComponent) -> maven.from(javaComponent)));
project.getPlugins().withType(JavaPlugin.class, (plugin) -> {
maven.from(project.getComponents().getByName("java"));
});
project.getPlugins().withType(JavaPlatformPlugin.class, (plugin) -> {
maven.from(project.getComponents().getByName("javaPlatform"));
});
}
});
});