Skip to content

Commit

Permalink
Fix javadoc/sources publishing (#220)
Browse files Browse the repository at this point in the history
This commit fixes javadocs and sources publishing for modules which use
shadow jar: in this case, the publishing mechanism does NOT use standard
Gradle publications. This caused the javadocs/sources to be ignored.

In order to check that publishing works properly, there's now the
possibility to override the default sonatype URIs, in order to verify
publication locally for example.

The following env vars/system properties were added:

- allowInsecurePublishing: lets Gradle publish on a repository which
doesn't use https. Useful for dry run deployments on local repos
- SONATYPE_REPO_URI/sonatypeRepoUri : the URI of a sonatype server where
to publish releases
- SONATYPE_SNAPSHOT_REPO_URI/sonatypeSnapshotRepoUri: the URI of a nexus
repository where to publish snapshots
  • Loading branch information
melix authored Oct 28, 2021
1 parent da98b60 commit 6c4fb12
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,15 @@ class MicronautPublishingPlugin implements Plugin<Project> {
}

if(project.hasProperty('shadowJarEnabled') && project.shadowJarEnabled == true) {
// TODO: This code doesn't use Gradle publications, it hard codes publishing
// which is easy to break and causes Gradle Module Metadata to be ignored
// this should be replaced with a publication
def shadowJar = tasks.findByName("shadowJar")
artifact(project.tasks.shadowJar) {
classifier = null
}
artifact(tasks.named('javadocJar'))
artifact(tasks.named('sourcesJar'))
pom.withXml { xml ->
def xmlNode = xml.asNode()
def dependenciesNode = xmlNode.appendNode('dependencies')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public void apply(Settings settings) {

private void applyPublishingPlugin(Settings settings) {
ProviderFactory providers = settings.getProviders();
String ossUser = envOrSystemProperty(providers, "SONATYPE_USERNAME", "sonatypeOssUsername");
String ossPass = envOrSystemProperty(providers, "SONATYPE_PASSWORD", "sonatypeOssPassword");
String ossUser = envOrSystemProperty(providers, "SONATYPE_USERNAME", "sonatypeOssUsername", "");
String ossPass = envOrSystemProperty(providers, "SONATYPE_PASSWORD", "sonatypeOssPassword", "");
if (!ossUser.isEmpty() && !ossPass.isEmpty()) {
settings.getGradle().projectsLoaded(gradle -> configureNexusPublishing(gradle, ossUser, ossPass));
}
Expand All @@ -61,10 +61,11 @@ private void configureNexusPublishing(Gradle gradle, String ossUser, String ossP
nexusPublish.getRepositoryDescription().set("" + rootProject.getGroup() + ":" + rootProject.getName() + ":" + rootProject.getVersion());
nexusPublish.getUseStaging().convention(!rootProject.getVersion().toString().endsWith("-SNAPSHOT"));
nexusPublish.repositories(repos -> repos.create("sonatype", repo -> {
repo.getAllowInsecureProtocol().convention(rootProject.getProviders().systemProperty("allowInsecurePublishing").forUseAtConfigurationTime().map(Boolean::parseBoolean).orElse(false));
repo.getUsername().set(ossUser);
repo.getPassword().set(ossPass);
repo.getNexusUrl().set(uri("https://s01.oss.sonatype.org/service/local/"));
repo.getSnapshotRepositoryUrl().set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"));
repo.getNexusUrl().set(uri(envOrSystemProperty(rootProject.getProviders(), "SONATYPE_REPO_URI", "sonatypeRepoUri", "https://s01.oss.sonatype.org/service/local/")));
repo.getSnapshotRepositoryUrl().set(uri(envOrSystemProperty(rootProject.getProviders(), "SONATYPE_SNAPSHOT_REPO_URI", "sonatypeSnapshotsRepoUri", "https://s01.oss.sonatype.org/content/repositories/snapshots/")));
repo.getStagingProfileId().set(NEXUS_STAGING_PROFILE_ID);
}));
}
Expand All @@ -77,11 +78,11 @@ private static URI uri(String uri) {
}
}

private static String envOrSystemProperty(ProviderFactory providers, String envName, String propertyName) {
private static String envOrSystemProperty(ProviderFactory providers, String envName, String propertyName, String defaultValue) {
return providers.environmentVariable(envName)
.forUseAtConfigurationTime()
.orElse(providers.gradleProperty(propertyName).forUseAtConfigurationTime())
.getOrElse("");
.getOrElse(defaultValue);
}

private void configureGradleEnterprise(Settings settings, GradleEnterpriseExtension ge) {
Expand Down

0 comments on commit 6c4fb12

Please sign in to comment.