We are working on migrating our current custom plugins from groovy to java and are facing issues getting publications to work. What we want to achieve is to have some jars/zips published onto one out of two maven repos (depending or “type of release” we would post to different repos).
Here is the java code that create the publication that causes the failure:
public class SetupPublicationTask extends DefaultTask {
@TaskAction
public void execute() {
Project project = getProject();
project.getLogger().info("Creating Maven publication with name mavenJava");
MavenPublication publication = project.getExtensions().getByType(PublishingExtension.class).getPublications()
.create("mavenJava", MavenPublication.class);
publication.from(project.getComponents().getByName("java"));
publication.setGroupId(project.getGroup().toString());
publication.setArtifactId(project.getName());
PublishArtifactSet artifactSet = project.getConfigurations().getByName("archives").getArtifacts();
ArrayList<PublishArtifact> artifacts = new ArrayList<>(artifactSet);
project.getLogger().info("Adding archives: {} to Maven publication...", artifacts.stream()
.map(a -> a.getName()+ "-"+a.getExtension()).collect(Collectors.joining(",")));
publication.setArtifacts(artifacts);
}
}
This fails with error:
A problem was found with the configuration of task ‘:release’.
> No value has been specified for property ‘publication.publishableFiles’.
The working groovy code looks like
Task createUploadLibraryTask(Project addToProject, boolean isProductionRelease, String repoUrl, String repoUser, String repoUserPass) {
String usedRepo = isProductionRelease ? LIBS_REPO : BETA_LIBS_REPO
project.logger.info("Using library repo: {}",usedRepo)
addToProject.plugins.apply('maven-publish')
addToProject.publishing {
publications {
mavenJava(MavenPublication) {
from addToProject.components.java
artifact addToProject.sourceJar {
classifier "sources"
}
artifact addToProject.javadocJar {
classifier "javadoc"
}
}
}
repositories {
maven {
url repoUrl+"/"+usedRepo
credentials {
username repoUser
password repoUserPass
}
}
}
}
Task publishTask = addToProject.getTasks().getByPath("publish")
return publishTask;
}