bintray / gradle-bintray-plugin

Apache License 2.0
1.28k stars 194 forks source link

Multiproject publish - problem with subproject and "allProjects" block #302

Open RareScrap opened 4 years ago

RareScrap commented 4 years ago

Hello. I have a rootproject with 2 subproject. And I want to publish them on bintray. To get started, I put the publication script in a separate file:

/*
Это просто блядский пиздец, товарищи. Сколько я не ебался, не получилось у меня
написать скрпит для юзания в allProjects. Вам кажется что этот код можно сделать лучше?
Ну так вперед! Но говно тут не просто так распихано...
 */

// Подготавливает maven-публикацию, которая будет использоваться в bintray
// Именно тут определяются артефакты для публикации
apply plugin: 'maven-publish'
publishing {
//        afterEvaluate { // TODO: Этим говном я пытался подбирать имя проекта в allProjects после того как оно назначится
    publications {
        "$project.name"(MavenPublication) {
                //from components.java // Артефакты по умолчанию. Отлючаем их, т.к. нам нужно артефакт main-модуля заменить на артефакт от api-модуля
                groupId group
                artifactId archivesBaseName
//                version "0.4.0_1.7.10" // TODO: Это для дебага, ибо project.version может не подобраться в allProjects
                version "${project.version}_1.7.10"
                artifact deobfJar
                artifact sourcesJar
                artifact javadocJar
        }
    }
//        }

}

// Публикация либы в bintray/jcenter
apply plugin: 'com.jfrog.bintray'
bintray {
    user = 'rarescrap'
    key = System.getenv('BINTRAY_KEY')
    publications = ["$project.name"]
    dryRun = true // Для тестов
    pkg {
        repo = 'minecraft'
        name = 'weight-api'
        licenses = ['GPL-3.0']
        vcsUrl = 'https://github.com/RareScrap/WeightAPI.git'
        version {
//            afterEvaluate { // TODO: Точно такое же говно как и выше, но теперь для версии публикации на bintray. Не знаю поему, но case2 вообще не втупляет в эту запись
                    name = "0.4.0_1.7.10"
//                name = "${project.version}_1.7.10" // TODO: Как раз из-за case2. Он просто ставит 0.4.0
                released = new Date()
//            }
        }
    }
}

Then I in the root project I did this:

allprojects {
    apply from: "$rootDir/gradle/mcforge.gradle"
    group= "ru.rarescrap.weightapi"
    apply from: "$rootDir/gradle/bintray.gradle"
}

And got this:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':publishWeightAPIPublicationToMavenLocal'.
> Failed to publish publication 'WeightAPI' to repository 'mavenLocal'
   > Invalid publication 'WeightAPI': artifact file does not exist: 'C:\Users\DangerArea\Desktop\WeightAPI\build\libs\WeightAPI-dev.jar'

This happened due to the fact that the version was not set for the jar. I have added "afterEvaluate" so that the publication code correctly set the version:

apply plugin: 'maven-publish'
publishing {
    afterEvaluate { // TODO: Этим говном я пытался подбирать имя проекта в allProjects после того как оно назначится
        publications {
            "$project.name"(MavenPublication) {
                    //from components.java // Артефакты по умолчанию. Отлючаем их, т.к. нам нужно артефакт main-модуля заменить на артефакт от api-модуля
                    groupId group
                    artifactId archivesBaseName
    //                version "0.4.0_1.7.10" // TODO: Это для дебага, ибо project.version может не подобраться в allProjects
                    version "${project.version}_1.7.10"
                    artifact deobfJar
                    artifact sourcesJar
                    artifact javadocJar
            }
        }
    }
}

The result just hit me. The case2 subproject did not create its publication at all:

> Task :case1:bintrayUpload 
Uploading to https://api.bintray.com/content/rarescrap/minecraft/weight-api/0.4.0_1.7.10/ru/rarescrap/weightapi/weightapi-case1/0.4.0_1.7.10/weightapi-case1-0.4.0_1.7.10-dev.jar...
Uploading to https://api.bintray.com/content/rarescrap/minecraft/weight-api/0.4.0_1.7.10/ru/rarescrap/weightapi/weightapi-case1/0.4.0_1.7.10/weightapi-case1-0.4.0_1.7.10-sources.jar...
Uploading to https://api.bintray.com/content/rarescrap/minecraft/weight-api/0.4.0_1.7.10/ru/rarescrap/weightapi/weightapi-case1/0.4.0_1.7.10/weightapi-case1-0.4.0_1.7.10-javadoc.jar...
Uploading to https://api.bintray.com/content/rarescrap/minecraft/weight-api/0.4.0_1.7.10/ru/rarescrap/weightapi/weightapi-case1/0.4.0_1.7.10/weightapi-case1-0.4.0_1.7.10.pom...

> Task :case2:bintrayUpload 
Skipping upload for missing file 'C:\Users\DangerArea\Desktop\WeightAPI\examples\case2\build\libs\weightapi-case2-0.4.0-dev.jar'.
Skipping upload for missing file 'C:\Users\DangerArea\Desktop\WeightAPI\examples\case2\build\libs\weightapi-case2-0.4.0-sources.jar'.
Skipping upload for missing file 'C:\Users\DangerArea\Desktop\WeightAPI\examples\case2\build\libs\weightapi-case2-0.4.0-javadoc.jar'.
Skipping upload for missing file 'C:\Users\DangerArea\Desktop\WeightAPI\examples\case2\build\publications\case2\pom-default.xml'.

> Task :bintrayUpload 
Uploading to https://api.bintray.com/content/rarescrap/minecraft/weight-api/0.4.0_1.7.10/ru/rarescrap/weightapi/weightapi/0.4.0_1.7.10/weightapi-0.4.0_1.7.10-dev.jar...
Uploading to https://api.bintray.com/content/rarescrap/minecraft/weight-api/0.4.0_1.7.10/ru/rarescrap/weightapi/weightapi/0.4.0_1.7.10/weightapi-0.4.0_1.7.10-sources.jar...
Uploading to https://api.bintray.com/content/rarescrap/minecraft/weight-api/0.4.0_1.7.10/ru/rarescrap/weightapi/weightapi/0.4.0_1.7.10/weightapi-0.4.0_1.7.10-javadoc.jar...
Uploading to https://api.bintray.com/content/rarescrap/minecraft/weight-api/0.4.0_1.7.10/ru/rarescrap/weightapi/weightapi/0.4.0_1.7.10/weightapi-0.4.0_1.7.10.pom...

That's what the command `gradlew bintrayUpload --dry-run" say:


:safeClean SKIPPED
:case1:safeClean SKIPPED
:case2:safeClean SKIPPED
:compileApiJava SKIPPED
:processApiResources SKIPPED
:apiClasses SKIPPED
:sourceMainJava SKIPPED
:compileJava SKIPPED
:processResources SKIPPED
:classes SKIPPED
:deobfJar SKIPPED
:generatePomFileForWeightAPIPublication SKIPPED
:javadoc SKIPPED
:javadocJar SKIPPED
:sourcesJar SKIPPED
:publishWeightAPIPublicationToMavenLocal SKIPPED
:jar SKIPPED
:case1:downloadClient SKIPPED
:case1:downloadServer SKIPPED
:case1:getVersionJson SKIPPED
:case1:extractUserDev SKIPPED
:case1:mergeJars SKIPPED
:case1:applyBinPatches SKIPPED
:case1:downloadMcpTools SKIPPED
:case1:extractMcpData SKIPPED
:case1:genSrgs SKIPPED
:case1:deobfBinJar SKIPPED
:case1:compileApiJava SKIPPED
:case1:processApiResources SKIPPED
:case1:apiClasses SKIPPED
:case1:sourceMainJava SKIPPED
:case1:compileJava SKIPPED
:case1:processResources SKIPPED
:case1:classes SKIPPED
:case1:deobfJar SKIPPED
:case1:generatePomFileForCase1Publication SKIPPED
:case1:javadoc SKIPPED
:case1:javadocJar SKIPPED
:case1:sourcesJar SKIPPED
:case1:publishCase1PublicationToMavenLocal SKIPPED
:case1:bintrayUpload SKIPPED
:case2:bintrayUpload SKIPPED
:bintrayUpload SKIPPED
:bintrayPublish SKIPPED

As you can see the publication is not created for the case2. Guys, what am I doing wrong? How to write bintray publication script and put it into a separate file? At the same time, I want to apply it only once in allProjects, and not copy it to every build script. You can find all code here

dubinsky commented 4 years ago

@RareScrap Maybe my solution to the Bintray configuration sharing problem can be of help? P.S. Enjoyed code comments above immensely; I hope you don't mind me re-using one of them in my write-up :)