How to change the jar filename when upload to artifactory via gradle

时间秒杀一切 提交于 2019-12-20 05:50:28

问题


I am using gradle in order to upload jar to artifactory. I managed to do it however I am trying to change the jar filename but it doesnt really let me.

I am using shadowJar to package. this is how I do it:

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'idea'
apply plugin: 'maven-publish'
apply plugin: 'com.github.johnrengelman.shadow'



    shadowJar {
        classifier = ''
        baseName = 'com.mycompany.app-all'
        manifest {
            attributes 'Main-Class': 'com.mycompany.app.main.starter'
        }
    }


publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.shadow

            groupId 'com.mycompany'
            artifactId "app"
            version "${build_version}"
        }
    }
}

Now if build_version=2.1 than the dirs on artifactory will look like this:

http://repo.address:8081/artifactory/libs-release-local/com/mycompany/app/2.1/app-2.1.jar

I would like to keep the folder structure but change the jar filename(as defined in shadowJar)

and to have it this way:

http://repo.address:8081/artifactory/libs-release-local/com/mycompany/app/2.1/com.mycompany.app-all.jar

any idea?


回答1:


The Jar task default naming convention is

[baseName]-[appendix]-[version]-[classifier].[extension]

If you set just the basename, the remaining values get appended to it. To override, set archiveName instead of baseName

shadowJar {
    ...
    archiveName = 'com.mycompany.app-all'
    ...
}

To change naming on what artifactory is publishing:

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.shadow

            groupId 'com.mycompany'
            artifactId 'com.mycompany.app-all' //<-- changed here
            version ''                         // and here
        }
    }
}


来源:https://stackoverflow.com/questions/35155345/how-to-change-the-jar-filename-when-upload-to-artifactory-via-gradle

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