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

使用gradle-maven-publish-plugin发布至Maven Central缺失主JAR包求助

Solution: Missing Main JAR When Publishing to Maven Central with vanniktech/gradle-maven-publish-plugin

Let’s break down why your main file-butler-0.1.4-SNAPSHOT.jar isn’t being pushed to Maven Central (even though local publishing works) and fix it step by step.

Possible Causes & Fixes

1. Redundant sourceSets Configuration Might Be Confusing the Plugin

Your current sourceSets block explicitly adds directories that are already included by default for Java/Kotlin projects:

sourceSets {
    main.kotlin.srcDirs += 'src/main/kotlin'
    main.java.srcDirs += 'src/main/java'
}

The java-library and Kotlin plugins automatically recognize these standard source directories. Manually appending them can disrupt how the plugin identifies the main JAR output.

Fix: Remove this entire sourceSets block from your module’s build.gradle. Let the plugins handle source directory detection natively.

2. Ensure the Plugin Is Properly Configured for Your Kotlin/Java Library

The com.vanniktech.maven.publish plugin relies on correctly identifying the publication component. For Kotlin + Java Library projects, you may need to explicitly tie the publication to the Kotlin component (since Kotlin generates its own JAR alongside the Java one).

Add this configuration to your module’s build.gradle to define your publication details clearly:

mavenPublish {
    // Replace with your actual group, artifact ID, and version
    coordinates("your.group.id", "file-butler", "0.1.4-SNAPSHOT")
    publishToMavenCentral()
    // Required for Maven Central publishing
    signAllPublications()
}

If issues persist, explicitly link the publication to the Kotlin component in an afterEvaluate block:

afterEvaluate {
    publishing {
        publications {
            mavenJava(MavenPublication) {
                from components.kotlin
            }
        }
    }
}

3. Upgrade the Plugin Version (If Compatibility Permits)

You’re using version 0.13.0 of the plugin, which is quite outdated (released in 2020). Newer versions fix compatibility bugs with Kotlin and Gradle plugins, especially around publication component detection.

For your Gradle 4.1.0 + Kotlin 1.4.10 setup, version 0.22.0 is a compatible stable choice. Update the classpath in your root build.gradle.kts:

classpath("com.vanniktech:gradle-maven-publish-plugin:0.22.0")

4. Check Verbose Logs for Task Execution Clues

Run the publish command with verbose logging to see if the main JAR task is being skipped or failing:

./gradlew publish -i

Look for lines related to jar or kotlinJar tasks. If they’re not executed, it means the plugin isn’t triggering them—pointing to a component misconfiguration.

Test the Fix

After applying changes, first verify local publishing still generates the main JAR:

./gradlew publishToMavenLocal

Check your local Maven repo (usually ~/.m2/repository) to confirm file-butler-0.1.4-SNAPSHOT.jar exists alongside the sources and javadoc JARs, then proceed with publishing to Maven Central.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.09 21:22:34