Skip to content

Commit

Permalink
Disable the creation of the default publication.
Browse files Browse the repository at this point in the history
  • Loading branch information
marchermans committed Jan 8, 2025
1 parent d43e998 commit 7a9037b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.gradle.api.provider.Provider;
import org.gradle.api.publish.PublishingExtension;
import org.gradle.api.publish.maven.*;
import org.gradle.api.tasks.Input;
import org.gradle.internal.instrumentation.api.annotations.ToBeReplacedByLazyProperty;

import javax.inject.Inject;
Expand All @@ -19,7 +20,7 @@
/**
* Extension that configures the Maven publishing plugin.
*/
public class MavenPublishingExtension {
public abstract class MavenPublishingExtension {

/**
* Gets the Maven publishing extension for the given project.
Expand Down Expand Up @@ -62,6 +63,23 @@ public boolean includedInMaven() {
public MavenPublishingExtension(final Project project) {
this.project = project;
this.configurators = new LinkedList<>();

this.getShouldCreateDefaultPublication().convention(true);
}

/**
* Indicates whether tableau should create a default publication.
*
* @return whether tableau should create a default publication
*/
@Input
public abstract Property<Boolean> getShouldCreateDefaultPublication();

/**
* Disables the default publication.
*/
public void disableDefaultPublication() {
getShouldCreateDefaultPublication().set(false);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ private void configurePublication(Project project) {
final MavenPublishingExtension mavenPublishing = MavenPublishingExtension.get(project);

project.afterEvaluate(ignored -> {
//This needs to be in an after evaluate block to ensure that the project has been configured.
publishing.getPublications().create("default", MavenPublication.class, publication -> {
publication.from(project.getComponents().getByName("java"));
});
if (mavenPublishing.getShouldCreateDefaultPublication().get()) {
//This needs to be in an after evaluate block to ensure that the project has been configured.
publishing.getPublications().create("default", MavenPublication.class, publication -> {
publication.from(project.getComponents().getByName("java"));
});
}

publishing.getPublications().withType(MavenPublication.class).configureEach(publication -> {
publication.pom(mavenPublishing::configure);
Expand Down

0 comments on commit 7a9037b

Please sign in to comment.