Gradle Multi项目构建前缀jar和maven出版物

时间:2016-12-08 14:01:51

标签: gradle build.gradle

我有一个gradle多项目构建,具有以下布局:

    Root
     +---ProjectA
     +---ProjectB
     +---ProjectC
     +    ...

子项目将生产的罐子需要加上前缀。例如PREFIX-ProjectA.jar。那是有效的。

如何告诉maven-publish任务它搜索" PREFIX-ProjectA.jar"?目前,它搜索" ProjectA.jar"

我的发布部分如下所示:

    task sourceJar(type: Jar) {
        baseName 'PREFIX-' + project.name
        from sourceSets.main.allJava
    }

    publishing {
        publications {
            mavenJava(MavenPublication) {

                artifactId 'PREFIX-' + project.name

                from components.java

                artifact sourceJar {
                    classifier "sources"
                }
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

如果某人遇到同样的问题,这是我的解决方案:

    /**
     * Creates a jar containing all sources
     */
    task jarSources(type: Jar) {
        baseName = 'PREFIX-' + project.name
        from sourceSets.main.allJava
        classifier = 'sources'
    }

    /**
     * Creates the jar file
     */
    task jarExecutable(type: Jar) {
        baseName = 'PREFIX-' + project.name
        from sourceSets.main.output
    }

    publishing {
        publications {
            mavenJava(MavenPublication) {
                artifactId 'PREFIX-' + project.name

                artifact jarExecutable

                artifact jarSources

                //....
            }
        }   
    }