[英]How to upload an existing collection of 3rd-party Jars to a Maven server in Gradle?
How can I upload a collection of existing Jars to a Maven repository? 如何将现有Jars的集合上载到Maven存储库? The Jars are built from an ANT Task imported to Gradle, and used as a dependency to my task... The Jars don't have version tag, so they should ALL receive the same version number when they are uploaded...
Jars是从导入到Gradle的ANT任务构建的,并用作我的任务的依赖... ... Jars没有版本标记,所以他们应该在上传时收到相同的版本号...
apply plugin: 'java'
apply plugin: 'maven'
version = "6.1.1"
group = "com.oahu"
ant.importBuild "$projectDir/tools/ant/package.xml"
uploadArchives(dependsOn: ["oahu-jar", "client-sdk-jar", "common-jar"]) << {
// the dependencies will generate "oahu.jar", "oahu_client_sdk.jar", "common.jar"
// UPLOAD THE DEPENDENCIES LISTED ABOVE LOCATED AT the subdirectory "build/"
description = "Uploads the generated jar ${archivesBaseName}-${version}.jar to ${cn_mvn_serverUrl}"
repositories.mavenDeployer {
repository(url: "${cn_mvn_releaseUrl}") {
authentication(userName: "${cn_mvn_username}", password: "${cn_mvn_password}")
}
}
}
The tasks "oahu-jar", "client-sdk-jar", "common-jar" are the ones imported from ANT... I have the Maven repositories configuration already working from another project... But the Maven plugin uploads the Jar generated by the Jar task from the Java plugin... Considering the imported ANT tasks generates: 任务“oahu-jar”,“client-sdk-jar”,“common-jar”是从ANT导入的...我有Maven存储库配置已经在另一个项目中工作......但是Maven插件上传了Jar插件从Jar插件生成Jar ...考虑导入的ANT任务生成:
The result of this should be the upload of those Jars with the given version... 结果应该是使用给定版本上传那些Jars ...
"oahu-6.1.1.jar", "oahu_client_sdk-6.1.1.jar", "common-6.1.1.jar"... all uploaded to the Maven repository... “oahu-6.1.1.jar”,“oahu_client_sdk-6.1.1.jar”,“common-6.1.1.jar”......全部上传到Maven存储库......
Add sourceSets? 添加sourceSet? Configuration?
组态? Artifacts?
文物?
currently that is not explicitly supported by gradle so you have to do some scripting for that. 目前gradle没有明确支持,所以你必须为此做一些脚本。 Based on your snippet above, I've created a sample snippet, that should be easy to adapt:
根据上面的代码段,我创建了一个示例代码段,应该很容易适应:
apply plugin:'java'
apply plugin:'maven'
import org.gradle.api.internal.artifacts.publish.DefaultPublishArtifact
version = "6.1.1"
group = "com.oahu"
ant.importBuild "$projectDir/tools/ant/package.xml"
// a list of the ant tasks that create a jar
// I assumed the following convention:
// ant task named "SampleAntJar-jar" creates the jar "build/SampleAntJar.jar"
def antJarTasks = ["SampleAntJar-jar", "SecondSampleAntJar-jar"]
artifacts{
//for each ant task add a defaultpublishArtifact to the archives configuration
antJarTasks.each{ taskName ->
def artifactName = taskName - '-jar'
archives new DefaultPublishArtifact(artifactName, "jar", "jar", null, new
Date(), new File("$buildDir", "${artifactName}.jar"))
}
}
uploadArchives(){
dependsOn: antJarTasks
repositories {
mavenDeployer {
repository(url: "file://{'/Users/Rene/.m2/repository/'}")
antJarTasks.each{ antJarTask ->
antJarName = antJarTask - "-jar"
addFilter(antJarName) {artifact, file ->
artifact.name == antJarName
}
pom(antJarName).artifactId = antJarName
}
}
}
}
regards, René 问候,René
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.