您可以使用 IntelliJ 原生导入器Eclipse Buildship 在 IDE 中打开此示例。

此示例展示了如何使用 Gradle 将 Groovy 库发布到存储库。

my-library/build.gradle.kts
plugins {
    groovy
    `maven-publish`
}

version = "1.0.2"
group = "org.gradle.sample"

repositories {
    mavenCentral()
}

dependencies {
    implementation("org.codehaus.groovy:groovy-all:3.0.18")
}

publishing {
    publications {
        create<MavenPublication>("library") {
            from(components["java"])
        }
    }
    repositories {
        maven {
            url = uri(layout.buildDirectory.dir("publishing-repository"))
        }
    }
}
my-library/build.gradle
plugins {
    id 'groovy'
    id 'maven-publish'
}

version = '1.0.2'
group = 'org.gradle.sample'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.codehaus.groovy:groovy-all:3.0.18'
}

publishing {
    publications {
        library(MavenPublication) {
            from components.java
        }
    }
    repositories {
        maven {
            url = layout.buildDirectory.dir("publishing-repository")
        }
    }
}

要发布库

$ ./gradlew publish

BUILD SUCCESSFUL
4 actionable tasks: 4 executed
$ tree build/publishing-repository
build/publishing-repository/
└── org
    └── gradle
        └── sample
            └── my-library
                ├── 1.0.2
                │   ├── my-library-1.0.2.jar
                │   ├── my-library-1.0.2.jar.md5
                │   ├── my-library-1.0.2.jar.sha1
                │   ├── my-library-1.0.2.jar.sha256
                │   ├── my-library-1.0.2.jar.sha512
                │   ├── my-library-1.0.2.module
                │   ├── my-library-1.0.2.module.md5
                │   ├── my-library-1.0.2.module.sha1
                │   ├── my-library-1.0.2.module.sha256
                │   ├── my-library-1.0.2.module.sha512
                │   ├── my-library-1.0.2.pom
                │   ├── my-library-1.0.2.pom.md5
                │   ├── my-library-1.0.2.pom.sha1
                │   ├── my-library-1.0.2.pom.sha256
                │   └── my-library-1.0.2.pom.sha512
                ├── maven-metadata.xml
                ├── maven-metadata.xml.md5
                ├── maven-metadata.xml.sha1
                ├── maven-metadata.xml.sha256
                └── maven-metadata.xml.sha512

5 directories, 20 files

有关更多信息,请参阅 发布库