novoda / bintray-release

A helper for releasing from gradle up to bintray
Other
1.85k stars 208 forks source link

Plugin is publishing empty sources jar #262

Closed bruno-ortiz closed 2 years ago

bruno-ortiz commented 5 years ago

Scenario

When publishing my project artifacts to bintray or mavenLocal, since version 0.9, all directories inside the source jar of the project are empty.

Config

All configurations can be seen here: https://github.com/GuiaBolso/hyperloop

Thanks

mr-archano commented 5 years ago

@bruno-ortiz if it would be useful if you could please confirm whether your project has always been using Kotlin or not.

motorro commented 5 years ago

Here is what I've found when trying to deploy from windows machine and travis. I've noticed that deploying from windows works fine generating a valid source jar. However running on Linux the task generates an empty jar. Here is an abstract of my library build.gradle:

// Generates Kotlin sources
task sourcesJar(type: Jar, dependsOn: classes) {
    archiveClassifier.set('sources')
    from sourceSets.main.allSource
}
artifacts {
    archives sourcesJar
}
// Adds a dependency to upload (more about it later)
bintrayUpload.dependsOn assemble

And here is a task-list that is generated on my windows machine:

$ ./gradlew -m bintrayUpload -PbintrayUser=motorro -PbintrayKey=XXX -PdryRun=true --no-daemon

:base:compileKotlin SKIPPED
:base:compileJava SKIPPED
:base:processResources SKIPPED
:base:classes SKIPPED
:base:inspectClassesForKotlinIC SKIPPED
:base:jar SKIPPED
:base:sourcesJar SKIPPED
:base:assemble SKIPPED
:base:bintrayUpload SKIPPED

Compare to task list from Linux:

$ ./gradlew -m bintrayUpload -PbintrayUser=motorro -PbintrayKey=XXX -PdryRun=true --no-daemon

:base:compileKotlin SKIPPED
:base:compileJava SKIPPED
:base:processResources SKIPPED
:base:classes SKIPPED
:base:inspectClassesForKotlinIC SKIPPED
:base:jar SKIPPED
:base:sourcesJar SKIPPED
:base:assemble SKIPPED
:base:generatePomFileForMavenPublication SKIPPED 
:base:javadoc SKIPPED
:base:genereateJavadocsJarForMavenPublication SKIPPED
:base:genereateSourcesJarForMavenPublication SKIPPED
:base:publishMavenPublicationToMavenLocal SKIPPED
:base:bintrayUpload SKIPPED

Notice the task-list in Linux environment include publishMavenPublicationToMavenLocal which is not present for Windows. Why? This tasks depends on genereateJavadocsJarForMavenPublication and genereateSourcesJarForMavenPublication which, I believe, are defined here and here These tasks effectively overwrite the result of sourcesJar above resulting in empty source jar.

As a workaround for this one could disable individual tasks as @mr-archano suggests in #270 or disable the publishMavenPublicationToMavenLocal altogether which works for me in Travis deploy

mr-archano commented 5 years ago

@motorro thanks for the headsup.

Notice the task-list in Linux environment include publishMavenPublicationToMavenLocal which is not present for Windows. Why?

It sounds like the issue you are facing might be slightly different. Could you please ensure that you can reproduce the issue even after a project clean? If that is the case I'd prefer to track it as separate issue.

These tasks effectively overwrite the result of sourcesJar above resulting in empty source jar.

Instead of defining a new sourcesJar task you could try to configure genereateSourcesJarForMavenPublication to add from sourceSets.main.allSource. I believe the underlying issue here is that we should patch that task (PRs are welcome 😉). That in conjunction with more configurability (see #266) should allow for the most flexible solution.

motorro commented 5 years ago

@mr-archano Yes I've tried:

./gradlew -m clean bintrayUpload -PbintrayUser=xxx -PbintrayKey=xxx -PdryRun=true --no-daemon 

Just forgot it in my original post. And it is a separate issue for sure - I've just written it here to illustrate the problem search path. Spawned another one: #271

Instead of defining a new sourcesJar task you could try to configure genereateSourcesJarForMavenPublication to add from sourceSets.main.allSource

Yes, sure. But I've "discovered" that task only yesterday when came across Travis was uploading empty source jars. While the source generation for Kotlin code problem was the original one and I had no problem publishing from windows using your plugin. So this problem for me comes in a somewhat reversed order :) Anyway, I'm not a 80 lvl "graddler" unfortunately and may come to wrong solutions :(

mr-archano commented 5 years ago

Thanks very much @motorro for creating the new issue. I have shortage of windows machines to try to replicate the issue myself, I might need your help with this if you;re up for it :)

Anyway, I'm not a 80 lvl "graddler" unfortunately and may come to wrong solutions :(

Don't worry about how much experience you have with Gradle, we can figure it out all together - this is the beauty of opensource projects! For instance we could try to start having a functional tests to reproduce the issue consistently so we can work out a solution, PR the patch and release a new version of the plugin altogether. What do you think? Feel free to ping me in the Gradle slack if you want to continue this chat or if you have further questions :)

motorro commented 5 years ago

@mr-archano

For instance we could try to start having a functional tests to reproduce the issue consistently so we can work out a solution

Deal 👍 Will try to figure out the test and be back.

mr-archano commented 5 years ago

@motorro FYI we already have a functional test in place to check other things, so maybe you can look into how to add a case in there (we might need to introduce a 3rd type of project that is applying the kotlin plugin though): https://github.com/novoda/bintray-release/blob/master/plugin/core/src/test/groovy/com/novoda/gradle/release/ReleasePluginTest.groovy

motorro commented 5 years ago

@mr-archano I've managed to: 1) Make tests to run on windows 2) Add dummy pure-Kotlin and Kotlin-Android tests to project Code is currently available here Got few problems - not sure what to do with them. 1) I need help from a more experienced graddler to fix the source generation - I don't know (don't have enough time to figure out) how to get sourceSets property here to pass them to source-generation task. 2) Javadoc generation is a more complicated task as it uses the third-party plugin Dokka to generate javadoc. It requires a separate config and javadoc task augmentation. So we need to figure out what to do with it.

motorro commented 5 years ago

Here are the failing tests that reproduce the current issue:

shouldGenerateJavadocs[Kotlin project with Gradle 4.10]
    expected outcome of task ':javadoc' to be: SUCCESS
    but was                                  : NO_SOURCE
    at com.novoda.gradle.truth.BuildTaskSubject$hasOutcome.call(Unknown Source)
    at com.novoda.gradle.release.ReleasePluginTest.shouldGenerateJavadocs(ReleasePluginTest.groovy:108)

shouldPackageAllGeneratedJavadocs[Kotlin project with Gradle 4.10]
    value of    : iterable.size()
    expected    : 0
    but was     : 1
    iterable was: ZIP 'C:\Users\motorro\Work\Projects\bintray-release\plugin\core\build\test- projects\com.novoda.gradle.release.ReleasePluginTest\Kotlin project with Gradle 4.10\test\build\libs\test-javadoc.jar'
    at com.google.common.truth.IterableSubject$hasSize.call(Unknown Source)
    at com.novoda.gradle.release.ReleasePluginTest.shouldPackageAllGeneratedJavadocs(ReleasePluginTest.groovy:118)

shouldPackageAllSources[Kotlin project with Gradle 4.10]
    value of    : iterable.size()
    expected    : 1
    but was     : 0
    iterable was: ZIP 'C:\Users\motorro\Work\Projects\bintray-release\plugin\core\build\test-projects\com.novoda.gradle.release.ReleasePluginTest\Kotlin project with Gradle 4.10\test\build\libs\test-sources.jar'
    at com.google.common.truth.IterableSubject$hasSize.call(Unknown Source)
    at com.novoda.gradle.release.ReleasePluginTest.shouldPackageAllSources(ReleasePluginTest.groovy:131)
mr-archano commented 5 years ago

@motorro thanks for the updates! I have spent last week travelling, but I am planning to take a look at this as soon as I can. I will keep you posted :)

mattmook commented 5 years ago

I'm using the following to fix the sources jar in one my projects until the plugin is updated to fix pure Kotlin projects:

tasks.whenTaskAdded {
    if (name == "generateSourcesJarForMavenPublication") {
        this as Jar
        from(sourceSets.main.get().allSource)
    }
}