How to upload an existing collection of 3rd-party Jars to a Maven server in Gradle?

这一生的挚爱 提交于 2019-12-05 14:39:22

currently that is not explicitly supported by gradle so you have to do some scripting for that. 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é

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!