简体   繁体   English

如何将现有的第三方JAR集合上传到Gradle中的Maven服务器?

[英]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任务生成:

  • build.gradle 的build.gradle
  • src SRC
  • build |-"oahu.jar" |-"oahu_client_sdk.jar" |-"common.jar" build | - “oahu.jar”| - “oahu_client_sdk.jar”| - “common.jar”

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.

相关问题 Maven:将第三方jar的导出jar添加到manifest中的classpath - Maven: Export jar with 3rd-party jars added to classpath in manifest 使用maven-android-plugin不能将第三方jar包含到Android应用程序中 - Cannot include 3rd-party jars into Android application with the maven-android-plugin 如何在 Maven POM 中处理 3rd 方 JAR 和远程存储库? - How to handle 3rd party JARs and remote repository in Maven POM? 在解决依赖关系之前,使用Maven安装第三方依赖关系 - Install a 3rd-party dependency with maven before dependencies are resolved 添加带有Maven软件包的3rd Party Jars - Add 3rd Party Jars with Maven Package 当第三方Java库作为单个jar的集合提供时,将它集成到Maven项目中的最佳方法是什么? - When a 3rd party Java library is supplied as a collection of individual jars, what is the best way to integrate it in a Maven project? Maven:是否可以将一组第三方罐子上传到存储库,然后将其作为单个依赖项引用? - Maven: Is it possible to upload a set of 3rd party jars to repository, which can then be referenced as a single dependency? 如何将第3方jars的依赖项添加到android-maven项目中 - How do I add dependencies for 3rd party jars in to an android-maven project 使用Nexus中的Maven为第3方jar创建存储库 - To create a repository for 3rd party jars using Maven in Nexus 将大量的第三方罐子合并到行家中 - Incorporate large number of 3rd party jars into maven
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM