Skip to content

Commit

Permalink
By default add java publication (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
ferozco authored Jul 10, 2023
1 parent 4ffe029 commit 506cffc
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.theoremlp.github.packages;

import java.util.Collections;
import java.util.function.Consumer;
import java.util.stream.Stream;
import nebula.plugin.info.scm.ScmInfoPlugin;
import nebula.plugin.publishing.maven.MavenBasePublishPlugin;
Expand All @@ -27,6 +28,7 @@
import org.gradle.api.plugins.JavaLibraryPlugin;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.publish.PublishingExtension;
import org.gradle.api.publish.maven.MavenPublication;
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin;
import org.gradle.api.publish.tasks.GenerateModuleMetadata;
import org.gradle.jvm.tasks.Jar;
Expand All @@ -41,11 +43,21 @@ public void apply(Project project) {
project.getRepositories().getByName(GithubPackagesExtension.GITHUB_REPO_DEFAULT_NAME);
PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class);
publishing.getRepositories().add(githubRepo);
addPublication(
project, "maven", maven -> maven.from(project.getComponents().getByName("java")));

configureJars(project);
disableModuleMetadata(project);
}

public void addPublication(
Project project, String publicationName, Consumer<MavenPublication> publicationConfiguration) {
project.getExtensions().getByType(PublishingExtension.class).publications(publications -> {
MavenPublication mavenPublication = publications.maybeCreate(publicationName, MavenPublication.class);
publicationConfiguration.accept(mavenPublication);
});
}

private static void configureJars(Project project) {
project.getTasks().withType(Jar.class).named("jar").configure(jar -> {
jar.getManifest().attributes(Collections.singletonMap("Implementation-Version", project.getVersion()));
Expand Down

0 comments on commit 506cffc

Please sign in to comment.