You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何仅将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::UnsupportedPackaging error happens because the auto-generated POM didn't specify a packaging type. Adding pom.packaging = 'jar' tells packagecloud exactly what kind of artifact this is.
  • The tar upload error occurs because the distribution plugin automatically adds distTar to the archives configuration—our fixes either remove it from archives or filter it out before upload.

内容的提问来源于stack exchange,提问作者injecteer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 07:29:16