Skip to content
This repository has been archived by the owner on Jan 18, 2021. It is now read-only.

Commit

Permalink
Merge pull request #742 from mockito/fix-ids
Browse files Browse the repository at this point in the history
Fix ordering issue with setting artifact name
  • Loading branch information
mockitoguy authored Jul 27, 2018
2 parents 52ea2fe + 500e647 commit fe138d1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.shipkit.internal.gradle.java;

import org.gradle.api.*;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.file.CopySpec;
import org.gradle.api.tasks.bundling.Jar;
import org.shipkit.internal.gradle.util.JavaPluginUtil;
Expand Down Expand Up @@ -37,28 +39,20 @@ public class JavaLibraryPlugin implements Plugin<Project> {
public void apply(final Project project) {
project.getPlugins().apply("java");

final CopySpec license = project.copySpec(new Action<CopySpec>() {
public void execute(CopySpec copy) {
copy.from(project.getRootDir()).include("LICENSE");
}
});
final CopySpec license = project.copySpec(copy -> copy.from(project.getRootDir()).include("LICENSE"));

((Jar) project.getTasks().getByName("jar")).with(license);

final Jar sourcesJar = project.getTasks().create(SOURCES_JAR_TASK, Jar.class, new Action<Jar>() {
public void execute(Jar jar) {
jar.from(JavaPluginUtil.getMainSourceSet(project).getAllSource());
jar.setClassifier("sources");
jar.with(license);
}
final Jar sourcesJar = project.getTasks().create(SOURCES_JAR_TASK, Jar.class, jar -> {
jar.from(JavaPluginUtil.getMainSourceSet(project).getAllSource());
jar.setClassifier("sources");
jar.with(license);
});

final Task javadocJar = project.getTasks().create(JAVADOC_JAR_TASK, Jar.class, new Action<Jar>() {
public void execute(Jar jar) {
jar.from(project.getTasks().getByName("javadoc"));
jar.setClassifier("javadoc");
jar.with(license);
}
final Task javadocJar = project.getTasks().create(JAVADOC_JAR_TASK, Jar.class, jar -> {
jar.from(project.getTasks().getByName("javadoc"));
jar.setClassifier("javadoc");
jar.with(license);
});

project.getArtifacts().add("archives", sourcesJar);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package org.shipkit.internal.gradle.java;

import org.gradle.api.Action;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;
import org.gradle.api.publish.PublicationContainer;
import org.gradle.api.publish.maven.MavenPublication;
import org.gradle.api.tasks.bundling.Jar;
import org.shipkit.gradle.configuration.ShipkitConfiguration;
import org.shipkit.internal.gradle.configuration.DeferredConfiguration;
import org.shipkit.internal.gradle.configuration.ShipkitConfigurationPlugin;
import org.shipkit.internal.gradle.snapshot.LocalSnapshotPlugin;
import org.shipkit.internal.gradle.util.GradleDSLHelper;
Expand Down Expand Up @@ -56,19 +55,17 @@ public void apply(final Project project) {
final Jar sourcesJar = (Jar) project.getTasks().getByName(JavaLibraryPlugin.SOURCES_JAR_TASK);
final Jar javadocJar = (Jar) project.getTasks().getByName(JavaLibraryPlugin.JAVADOC_JAR_TASK);

GradleDSLHelper.publications(project, new Action<PublicationContainer>() {
public void execute(PublicationContainer publications) {
MavenPublication p = publications.create(PUBLICATION_NAME, MavenPublication.class, new Action<MavenPublication>() {
public void execute(MavenPublication publication) {
publication.from(project.getComponents().getByName("java"));
publication.artifact(sourcesJar);
publication.artifact(javadocJar);
publication.setArtifactId(((Jar) project.getTasks().getByName("jar")).getBaseName());
PomCustomizer.customizePom(project, conf, publication);
}
GradleDSLHelper.publications(project, publications -> {
MavenPublication p = publications.create(PUBLICATION_NAME, MavenPublication.class, publication -> {
publication.from(project.getComponents().getByName("java"));
publication.artifact(sourcesJar);
publication.artifact(javadocJar);
DeferredConfiguration.deferredConfiguration(project, () -> {
publication.setArtifactId(((Jar) project.getTasks().getByName("jar")).getBaseName());
});
LOG.info("{} - configured '{}' publication", project.getPath(), p.getArtifactId());
}
PomCustomizer.customizePom(project, conf, publication);
});
LOG.info("{} - configured '{}' publication", project.getPath(), p.getArtifactId());
});

//so that we flesh out problems with maven publication during the build process
Expand Down

0 comments on commit fe138d1

Please sign in to comment.