运行 publishToMavenLocal 之后,maven 本地存储库中未生成 jar 文件

jar file is not getting generated in maven local repository after running publishToMavenLocal

我正在尝试生成一个 jar,以便我可以将它用作不同项目的依赖项。 在 build.gradle 中,我定义了 maven-publish id 和发布任务,但只生成了以下文件 - 但我需要 custom-codegen-0.0.1-SNAPSHOT.jar

custom-codegen-0.0.1-SNAPSHOT-plain.jar
custom-codegen-0.0.1-SNAPSHOT.module
custom-codegen-0.0.1-SNAPSHOT.pom
maven-metadata-local.xml

build.gradle

plugins {
    id 'org.springframework.boot' version '2.5.6'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
    id 'maven-publish'
}

group = 'com.tmo5'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

test {
    useJUnitPlatform()
}


publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
            versionMapping {
                usage('java-api') {
                    fromResolutionOf('runtimeClasspath')
                }
                usage('java-runtime') {
                    fromResolutionResult()
                }
            }
        }
    }
    repositories {
        maven {
            def releasesRepoUrl = "$buildDir/repos/releases"
            def snapshotsRepoUrl = "$buildDir/repos/snapshots"
            url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
        }
    }
}

除非您正在创建 Spring Boot 应用程序,否则不应应用 Spring Boot Gradle 插件。它并不意味着创建 Spring 引导库或一般的 Spring 库。它用于创建 Spring 启动应用程序。 Spring Boot Gradle 插件对应用于项目的各种插件做出反应,如 documentation.

中所述

其次,如果您希望您发布的工件被其他人使用,那么您应该改用 java-library

话虽如此,您的 Gradle 构建应该类似于:

plugins {
    id 'java-library'
    id 'maven-publish'
}

group = 'com.tmo5'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

repositories {
    mavenCentral()
}

dependencies {
    api platform('org.springframework.boot:spring-boot-dependencies:2.5.6')
    api 'org.springframework.boot:spring-boot-starter-web'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

test {
    useJUnitPlatform()
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
            versionMapping {
                usage('java-api') {
                    fromResolutionOf('runtimeClasspath')
                }
                usage('java-runtime') {
                    fromResolutionResult()
                }
            }
        }
    }
    repositories {
        maven {
            def releasesRepoUrl = "$buildDir/repos/releases"
            def snapshotsRepoUrl = "$buildDir/repos/snapshots"
            url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
        }
    }
}