我一直在尝试从我的自定义插件中设置publish(PublisherConfig),defaults(defaultsClosure)的属性。这样做的最佳方式是什么?
我尝试了以下内容;
方法1:尝试在扩展上设置属性
project.getExtensions().publishing.getProperties().each { println it }
方法2:尝试在Gradle Artifactory插件上添加编译时依赖项并导入插件类... ```
if (project.plugins.hasPlugin("com.jfrog.artifactory")) {
println "I found jfrog.artifactory plugin"
Plugin jfrogArtifactory = project.getPlugins().getPlugin("com.jfrog.artifactory")
ArtifactoryPluginConvention apc = new ArtifactoryPluginConvention(project);
project.getExtensions().add("artifactory", apc);
apc.contextUrl = 'https://myrepo.com/artifactory/'
PublisherConfig pc = new PublisherConfig(apc);
pc.defaults {
println "in my plugin pc.defaults : " + it.metaClass
publications('mavenJava')
publishConfigs('archives', 'published')
properties = ['my.gitCommitUrl': project.getExtensions().findByType(BuildPropertiesPluginExtension.class).gitCommitUrl, 'my.gitHash': project.getExtensions().findByType(BuildPropertiesPluginExtension.class).gitHash, 'my.gitBranch': project.getExtensions().findByType(BuildPropertiesPluginExtension.class).gitBranch]
publishBuildInfo = true //Publish build-info to Artifactory (true by default)
publishArtifacts = true //Publish artifacts to Artifactory (true by default)
publishPom = true //Publish generated POM files to Artifactory (true by default).
publishIvy = false //Publish generated Ivy descriptor files to Artifactory (true by default).
}
pc.repository {
println "in my plugin pc.repository : " + it.metaClass
repoKey = 'my-mvn' //The Artifactory repository key to publish to
username = project.findProperty("artifactory_user") ?: "" //The publisher user name
password = project.findProperty("artifactory_api_key") ?: "" //The publisher password
}
apc.setPublisherConfig(pc)
}
```
编译和构建成功,工件及其信息未发布。
:artifactoryPublish
建立成功
总时间:3.313秒
答案 0 :(得分:0)
这对我有用!!!
`
if (project.plugins.hasPlugin("com.jfrog.artifactory")) {
Plugin jfrogArtifactory = project.getPlugins().getPlugin("com.jfrog.artifactory")
//maven install task is required to publishPom (using artifactory plugin)
if (!project.plugins.hasPlugin("maven")) {
project.apply(plugin: MavenPlugin)
}
Closure artifactoryPublishClosure = {
contextUrl = 'https://myrepo.com/artifactory/'
publications('mavenJava')
publishConfigs('archives', 'published')
properties = ['gitCommitUrl': project.getExtensions().findByType(BuildPropertiesPluginExtension.class).gitCommitUrl, 'gitHash': project.getExtensions().findByType(BuildPropertiesPluginExtension.class).gitHash, 'gitBranch': project.getExtensions().findByType(BuildPropertiesPluginExtension.class).gitBranch]
publishBuildInfo = true //Publish build-info to Artifactory (true by default)
publishArtifacts = true //Publish artifacts to Artifactory (true by default)
publishPom = true //Publish generated POM files to Artifactory (true by default).
publishIvy = false //Publish generated Ivy descriptor files to Artifactory (true by default).
// Redefine basic properties of the build info object
clientConfig.setIncludeEnvVars(true)
clientConfig.timeout = 600 // Artifactory connection timeout (in seconds). The default timeout is 300 seconds.
publish {
//A closure defining publishing information
repository {
repoKey = 'my-mvn' //The Artifactory repository key to publish to
username = project.findProperty("artifactory_user") ?: "" //The publisher user name
password = project.findProperty("artifactory_api_key") ?: "" //The publisher password
}
}
resolve {
repository {
repoKey = 'my-mvn' //The Artifactory (preferably virtual) repository key to resolve from
}
}
}
project.getTasks().findByName("artifactoryPublish").configure(artifactoryPublishClosure)
}
`