[英]How do I publish Gradle plugins to Artifactory?
I am working with this example Gradle Plugin project: https://github.com/AlainODea/gradle-com.example.hello-plugin我正在使用这个示例 Gradle 插件项目: https : //github.com/AlainODea/gradle-com.example.hello-plugin
When I run ./gradlew publishToMavenLocal it creates these files in M2_HOME:当我运行./gradlew publishToMavenLocal 时,它会在 M2_HOME 中创建这些文件:
When I run ./gradlew artifactoryPublish it logs:当我运行./gradlew artifactoryPublish 时,它会记录:
Deploying artifact: https://artifactory.example.com/artifactory/libs-release-local-maven/com/example/hello/gradle-com.example.hello-plugin/0.1-SNAPSHOT/gradle-com.example.hello-plugin-0.1-SNAPSHOT.jar
Deploying artifact: https://artifactory.example.com/artifactory/libs-release-local-maven/com/example/hello/gradle-com.example.hello-plugin/0.1-SNAPSHOT/gradle-com.example.hello-plugin-0.1-SNAPSHOT.pom
Deploying build descriptor to: https://artifactory.example.com/artifactory/api/build
Build successfully deployed. Browse it in Artifactory under https://artifactory.example.com/artifactory/webapp/builds/gradle-com.example.hello-plugin/1234567890123
Attempting to load the plug-in from another build.gradle:尝试从另一个 build.gradle 加载插件:
plugins {
id 'java'
id 'com.example.hello' version '0.1-SNAPSHOT'
}
With settings.gradle:使用 settings.gradle:
pluginManagement {
repositories {
maven {
url 'https://artifactory.example.com/artifactory/libs-release-local-maven/'
}
}
}
Results in this error:导致此错误:
Plugin [id: 'com.example', version: '0.1-SNAPSHOT'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'com.example.hello:com.example.hello.gradle.plugin:0.1-SNAPSHOT')
Searched in the following repositories:
maven(https://artifactory.example.com/artifactory/libs-release-local-maven/)
Gradle Central Plugin Repository
I'd like to get all of the artifacts that publishToMavenLocal creates to be published to Artifactory when I run artifactoryPublish.我希望在运行 artifactoryPublish 时将 publishToMavenLocal 创建的所有工件发布到 Artifactory。 I am open to alternatives to artifactoryPublish if it is the wrong tool.如果它是错误的工具,我对 artifactoryPublish 的替代品持开放态度。
How do I publish Gradle plugins to Artifactory?如何将 Gradle 插件发布到 Artifactory?
Since you have the maven-publish plugin on, the java-gradle-plugin already declares publications for you, so you can remove this explicit publications block from your build:因为你有maven-publish插件, java-gradle-plugin已经为你声明了发布,所以你可以从你的构建中删除这个显式的发布块:
publishing {
publications {
create<MavenPublication>("mavenJava") {
from(components["java"])
}
}
}
You can then reference all automatically created publications in your artifactory publish defaults block as follows:然后,您可以在artifactory 发布默认块中引用所有自动创建的发布,如下所示:
invokeMethod("publications", publishing.publications.names.toTypedArray())
Why not just publishing.publications.names ?:为什么不只是publishations.publications.names ?:
Here's the complete, corrected artifactory block:这是完整的、更正的人工块:
artifactory {
setProperty("contextUrl", "https://artifactory.verafin.com/artifactory")
publish(delegateClosureOf<PublisherConfig> {
repository(delegateClosureOf<GroovyObject> {
setProperty("repoKey", "libs-release-local-maven")
})
defaults(delegateClosureOf<GroovyObject> {
invokeMethod("publications", publishing.publications.names.toTypedArray())
})
})
}
Here's a complete adaptation of your build.gradle.kts solving the problem:这是解决问题的 build.gradle.kts 的完整改编版:
import groovy.lang.GroovyObject
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jfrog.gradle.plugin.artifactory.dsl.PublisherConfig
buildscript {
repositories {
jcenter()
}
}
plugins {
`java-gradle-plugin`
`maven-publish`
`kotlin-dsl`
id("com.jfrog.artifactory") version "4.9.0"
kotlin("jvm") version "1.3.11"
id("io.spring.dependency-management") version "1.0.6.RELEASE"
}
group = "com.example.hello"
version = "0.1-SNAPSHOT"
gradlePlugin {
plugins {
create("helloPlugin") {
id = "com.example.hello"
implementationClass = "com.example.HelloPlugin"
}
}
}
repositories {
mavenCentral()
}
dependencyManagement {
imports {
mavenBom("org.junit:junit-bom:5.3.2")
}
}
dependencies {
implementation(kotlin("stdlib-jdk8"))
testImplementation(kotlin("test"))
testImplementation(kotlin("test-junit5"))
testImplementation("org.junit:junit-bom:latest.release")
testImplementation("org.junit.jupiter:junit-jupiter-api")
testImplementation("com.natpryce:hamkrest:1.7.0.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
}
tasks {
withType<JavaExec> {
jvmArgs = listOf("-noverify", "-XX:TieredStopAtLevel=1")
}
withType<KotlinCompile> {
val javaVersion = JavaVersion.VERSION_1_8.toString()
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
kotlinOptions {
apiVersion = "1.3"
javaParameters = true
jvmTarget = javaVersion
languageVersion = "1.3"
}
}
withType<Test> {
@Suppress("UnstableApiUsage")
useJUnitPlatform()
}
}
artifactory {
publish(delegateClosureOf<PublisherConfig> {
repository(delegateClosureOf<GroovyObject> {
setProperty("repoKey", "libs-release-local-maven")
})
defaults(delegateClosureOf<GroovyObject> {
invokeMethod("publications", publishing.publications.names.toTypedArray())
})
})
}
Here's a log showing the successful deployment of the plugin artifact to Artifactory:这是一个日志,显示了插件工件成功部署到 Artifactory:
Deploying artifact: https://artifactory.example.com/artifactory/libs-release-local-maven/com/example/hello/gradle-com.example.hello-plugin/0.1-SNAPSHOT/gradle-com.example.hello-plugin-0.1-SNAPSHOT.jar
Deploying artifact: https://artifactory.example.com/artifactory/libs-release-local-maven/com/example/hello/gradle-com.example.hello-plugin/0.1-SNAPSHOT/gradle-com.example.hello-plugin-0.1-SNAPSHOT.pom
Deploying artifact: https://artifactory.example.com/artifactory/libs-release-local-maven/com/example/hello/com.example.hello.gradle.plugin/0.1-SNAPSHOT/com.example.hello.gradle.plugin-0.1-SNAPSHOT.pom
Deploying build descriptor to: https://artifactory.example.com/artifactory/api/build
Build successfully deployed. Browse it in Artifactory under https://artifactory.example.com/artifactory/webapp/builds/gradle-com.example.hello-plugin/1234567890123
Since version 4.19 of the build-info-extractor-gradle plugin, there's an ALL_PUBLICATIONS
constant that can be used:从 build-info-extractor-gradle 插件的 4.19 版ALL_PUBLICATIONS
,可以使用一个ALL_PUBLICATIONS
常量:
artifactory {
publish {
contextUrl = 'https://url.com/artifactory'
repository {
// repoKey, etc. here
}
defaults {
publications 'ALL_PUBLICATIONS'
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.