如何仅将JAR包发布至packagecloud.io Maven仓库?
Got it, let's break down what's happening here and fix your issue:
When you run gradlew distTar, Gradle's uploadArchives is trying to upload all artifacts in the archives configuration—that includes your JAR, the distTar output, and even the auto-generated Maven POM. Packagecloud doesn't support tar files as Java artifacts, and the unconfigured POM is triggering a packaging validation error, which is why your build fails.
Here are two straightforward fixes to restrict uploads to only your JAR:
1. Explicitly define only the JAR in archives
The simplest approach is to clear out the default artifacts in archives (which includes distTar by default) and only add your JAR. Uncomment the line you had commented out, and we'll also fix the POM packaging issue while we're at it:
jar { archiveName "$project.name-$project.version-SNAPSHOT.jar" } distTar { archiveName 'dist.tar' } // Clear default artifacts (like distTar) from archives project.configurations.archives.artifacts.clear() artifacts { // Only add your JAR to the archives set archives(file("$buildDir/libs/$project.name-$project.version-SNAPSHOT.jar")) } uploadArchives { repositories.mavenDeployer { pom.version = project.version + '-SNAPSHOT' configuration = configurations.deployerJars repository(url: 'packagecloud+https://packagecloud.io/mycompany/central') { authentication password: pw } // Tell packagecloud this is a JAR artifact to fix packaging validation pom.packaging = 'jar' } } jar.finalizedBy uploadArchives
2. Filter artifacts directly in uploadArchives
If you prefer not to modify the archives configuration, you can add a filter to the uploadArchives task to only include JAR files:
// Keep your existing jar, distTar, artifacts config as-is uploadArchives { repositories.mavenDeployer { pom.version = project.version + '-SNAPSHOT' configuration = configurations.deployerJars repository(url: 'packagecloud+https://packagecloud.io/mycompany/central') { authentication password: pw } pom.packaging = 'jar' } // Filter out any non-JAR artifacts before uploading artifacts = artifacts.findAll { artifact -> artifact.file.name.endsWith('.jar') } } jar.finalizedBy uploadArchives
Quick notes on the errors:
- The
Unknown Java::Version::UnsupportedPackagingerror happens because the auto-generated POM didn't specify a packaging type. Addingpom.packaging = 'jar'tells packagecloud exactly what kind of artifact this is. - The tar upload error occurs because the distribution plugin automatically adds
distTarto thearchivesconfiguration—our fixes either remove it fromarchivesor filter it out before upload.
内容的提问来源于stack exchange,提问作者injecteer

