diff --git a/src/main/groovy/io/micronaut/build/MicronautPublishingPlugin.groovy b/src/main/groovy/io/micronaut/build/MicronautPublishingPlugin.groovy index afbe5c06..d3341a1c 100644 --- a/src/main/groovy/io/micronaut/build/MicronautPublishingPlugin.groovy +++ b/src/main/groovy/io/micronaut/build/MicronautPublishingPlugin.groovy @@ -147,10 +147,15 @@ class MicronautPublishingPlugin implements Plugin { } 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') diff --git a/src/main/java/io/micronaut/build/MicronautSharedSettingsPlugin.java b/src/main/java/io/micronaut/build/MicronautSharedSettingsPlugin.java index e7d85eeb..2dbe3bf0 100644 --- a/src/main/java/io/micronaut/build/MicronautSharedSettingsPlugin.java +++ b/src/main/java/io/micronaut/build/MicronautSharedSettingsPlugin.java @@ -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)); } @@ -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); })); } @@ -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) {