Skip to content

Ignore missing bintray environment in root project. #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hastebrot opened this issue May 11, 2015 · 20 comments
Closed

Ignore missing bintray environment in root project. #74

hastebrot opened this issue May 11, 2015 · 20 comments

Comments

@hastebrot
Copy link

Hey,

(I use gradle-bintray-plugin 1.2 and Gradle 2.4.)

I have a Gradle build configuration that contains an empty root project (no source sets) with tasks that call their counterparts in subprojects for convenience. The subprojects configure the bintray environent closure (i.e. user, key, pkg, ...).

The gradle-bintray-plugin adds the bintrayUpload task to the root project, but when I call it I get following error message:

FAILURE: Build failed with an exception.

* What went wrong:
Some problems were found with the configuration of task ':bintrayUpload'.
> No value has been specified for property 'packageName'.
> No value has been specified for property 'user'.
> No value has been specified for property 'apiKey'.
> No value has been specified for property 'repoName'.

Calling bintrayUpload on the subprojects works as expected.

It would be nice if the missing bintray environment closure could be ignored and the task in the root project could just call its counterpart bintrayUpload in the subprojects.

@hastebrot
Copy link
Author

Here is a quick workaround for this issue. I've added the following code to the top of my build.gradle build script to overwrite the root project's bintrayUpload task.

plugins {
    // use the bintray gradle plugin to upload build artifacts.
    id "com.jfrog.bintray" version "1.2"
}

// only our subprojects have a bintray configuration. replace the root project's 
// `bintrayUpload` task with one that restricts the calls to the subprojects.
project.afterEvaluate {
    task bintrayUpload(group: "publishing", overwrite: true) {
        dependsOn subprojects.bintrayUpload
    }
}

Also note that I used bintray { dryRun = true; /*...*/ }.

@jamescway
Copy link

+1 same problem. Thanks @hastebrot for the workaround wfm.

@abesto
Copy link

abesto commented Aug 11, 2015

Note, the workaround also disables version signing, publishing and maven sync from the plugin. These are defined in the original bintrayUpload task: https://github.com/bintray/gradle-bintray-plugin/blob/master/src/main/groovy/com/jfrog/bintray/gradle/BintrayUploadTask.groovy#L396-L404

@abesto
Copy link

abesto commented Aug 11, 2015

Another workaround: move the bintray section from subprojects to allprojects, then for the root project:

bintray {
    publications = []
    configurations = []
}

This just makes sure no artifacts are published for the (empty) root project, but everything else goes as normal. Or even specify the configurations / publications conditionally to avoid confusion:

allprojects { thisproject ->
    bintray {
        if (thisproject == rootProject) {
            configurations = []
        } else {
            configurations = ['archives']
        }
    }
}

@jamescway
Copy link

so in this case if the configuration is empty then gradle will not run any tasks on the root project.

@abesto
Copy link

abesto commented Aug 11, 2015

To clarify: the original Gradle task bintrayUpload will run, but incidentally it won't upload any artifacts due to the empty configurations. It will, however, sign the released version, publish the version, and/or sync to Maven Central if so configured. Why on the root project? Because the root project depends on all its subprojects, so the bintrayUpload task in the root project will be the last to run. And there's code in the plugin (at https://github.com/bintray/gradle-bintray-plugin/blob/master/src/main/groovy/com/jfrog/bintray/gradle/BintrayUploadTask.groovy#L395) that makes sure these after-upload actions are taken when the very last bintrayUpload task is executed.

@virl
Copy link

virl commented Aug 11, 2015

Please fix this.

How can I publish subproject to bintray without modifying root buildscript? Why do I have to modify root buildscript at all???

@DTHeaven
Copy link

DTHeaven commented Jan 2, 2016

This is my solution:
Complete project is here

  • Root build.gradle
buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.1'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

Note:Don't use apply plugin: 'com.jfrog.bintray'

  • Root gradle.properties
GROUP=im.quar
VERSION_NAME=1.0.0

POM_DESCRIPTION=AutoLayout for Android.

POM_URL=https://github.com/DTHeaven/AutoLayout-Android
POM_SCM_URL=https://github.com/DTHeaven/AutoLayout-Android
POM_SCM_CONNECTION=scm:git:git://github.com/DTHeaven/AutoLayout-Android.git
POM_SCM_DEV_CONNECTION=scm:git:ssh://[email protected]:DTHeaven/AutoLayout-Android.git
POM_ISSUE_URL=https://github.com/DTHeaven/AutoLayout-Android/issues

POM_LICENCE_NAME=The Apache Software License, Version 2.0
POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
POM_ALL_LICENCES=['Apache-2.0']
POM_LICENCE_DIST=repo

POM_DEVELOPER_ID=dtheaven
POM_DEVELOPER_NAME=DTHeaven
  • /gradle/gradle-mvn-push.gradle
/*
 * Copyright 2013 Chris Banes
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

apply plugin: 'com.jfrog.bintray'
apply plugin: 'com.github.dcendents.android-maven'

version = VERSION_NAME
group = GROUP

// Bintray
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

bintray {
    user = properties.getProperty("bintray.user")
    key = properties.getProperty("bintray.apikey")

    configurations = ['archives']
    pkg {
        repo = 'maven'
        name = POM_ARTIFACT_ID
        desc = POM_DESCRIPTION
        websiteUrl = POM_URL
        issueTrackerUrl = POM_ISSUE_URL
        vcsUrl = POM_SCM_URL
        licenses = ["Apache-2.0"]
        publish = true
        publicDownloadNumbers = true
        version {
            desc = POM_DESCRIPTION
            gpg {
                sign = true //Determines whether to GPG sign the files. The default is false
                passphrase = properties.getProperty("bintray.gpg.password")
                //Optional. The passphrase for GPG signing'
            }

            mavenCentralSync {
                sync = true
                user = properties.getProperty("bintray.oss.user")
                password = properties.getProperty("bintray.oss.password")
                close = '1'
            }
        }
    }
}

if (project.getPlugins().hasPlugin('com.android.application') ||
        project.getPlugins().hasPlugin('com.android.library')) {
    install {
        repositories.mavenInstaller {
            configuration = configurations.archives

            pom.groupId = GROUP
            pom.artifactId = POM_ARTIFACT_ID
            pom.version = VERSION_NAME

            pom.project {
                name POM_NAME
                packaging POM_PACKAGING
                description POM_DESCRIPTION
                url POM_URL

                scm {
                    url POM_SCM_URL
                    connection POM_SCM_CONNECTION
                    developerConnection POM_SCM_DEV_CONNECTION
                }

                licenses {
                    license {
                        name POM_LICENCE_NAME
                        url POM_LICENCE_URL
                        distribution POM_LICENCE_DIST
                    }
                }

                developers {
                    developer {
                        id POM_DEVELOPER_ID
                        name POM_DEVELOPER_NAME
                    }
                }
            }
        }
    }

    task androidJavadocs(type: Javadoc) {
        source = android.sourceSets.main.java.source
        classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    }

    task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
        classifier = 'javadoc'
        from androidJavadocs.destinationDir
    }

    task androidSourcesJar(type: Jar) {
        classifier = 'sources'
        from android.sourceSets.main.java.source
    }
} else {
    install {
        repositories.mavenInstaller {
            pom.groupId = GROUP
            pom.artifactId = POM_ARTIFACT_ID
            pom.version = VERSION_NAME

            pom.project {
                name POM_NAME
                packaging POM_PACKAGING
                description POM_DESCRIPTION
                url POM_URL

                scm {
                    url POM_SCM_URL
                    connection POM_SCM_CONNECTION
                    developerConnection POM_SCM_DEV_CONNECTION
                }

                licenses {
                    license {
                        name POM_LICENCE_NAME
                        url POM_LICENCE_URL
                        distribution POM_LICENCE_DIST
                    }
                }

                developers {
                    developer {
                        id POM_DEVELOPER_ID
                        name POM_DEVELOPER_NAME
                    }
                }
            }
        }
    }

    task sourcesJar(type: Jar, dependsOn: classes) {
        classifier = 'sources'
        from sourceSets.main.allSource
    }

    task javadocJar(type: Jar, dependsOn: javadoc) {
        classifier = 'javadoc'
        from javadoc.destinationDir
    }
}

if (JavaVersion.current().isJava8Compatible()) {
    allprojects {
        tasks.withType(Javadoc) {
            options.addStringOption('Xdoclint:none', '-quiet')
        }
    }
}

artifacts {
    if (project.getPlugins().hasPlugin('com.android.application') ||
            project.getPlugins().hasPlugin('com.android.library')) {
        archives androidSourcesJar
        archives androidJavadocsJar
    } else {
        archives sourcesJar
        archives javadocJar
    }
}
  • Subprojects
    • build.gradle
apply from: rootProject.file('gradle/gradle-mvn-push.gradle')
  • gradle.properties
POM_NAME=AutoLayout
POM_ARTIFACT_ID=autolayout
POM_PACKAGING=aar
POM_NAME=AutoLayout Annotations
POM_ARTIFACT_ID=autolayout-annotations
POM_PACKAGING=jar
POM_NAME=AutoLayout Compiler
POM_ARTIFACT_ID=autolayout-compiler
POM_PACKAGING=jar

@mitochondrion
Copy link

mitochondrion commented Apr 23, 2016

Note:Don't use apply plugin: 'com.jfrog.bintray'

@DTHeaven This fixed it for me. Thanks!

@milosmns
Copy link

milosmns commented Sep 4, 2016

Nope, not working for me. I even copied the whole repository and changed IDs to get it to work, still getting the same annoying error.

@milosmns
Copy link

milosmns commented Sep 4, 2016

OMG. Finally. The solution was to run gradle subproject:bintrayUpload instead of gradle bintrayUpload. This worked with Gradle 2.1 - No comment.

@eyalbe4
Copy link
Contributor

eyalbe4 commented Sep 5, 2016

@hastebrot, @milosmns, @mitochondrion, @DTHeaven and @jamescway,
I'd like to thank all of you for sharing all of the helpful information in this issue.
Do you think there's something we can add or improve in the plugin. that is related to this issue? if you don't, we'll close it.

@milosmns
Copy link

milosmns commented Sep 5, 2016

Well.. it would be a huge help if you could direct the command to the subproject when there is no bintray config in the root. But since I left a comment in my script, I won't be making the same mistake again :)

@eyalbe4
Copy link
Contributor

eyalbe4 commented Sep 5, 2016

Thanks @milosmns,
We've just implemented this (here's the commit).
This will be included as part of the next release.

@milosmns
Copy link

milosmns commented Sep 5, 2016

Thanks! Looking forward to it 👍

@eyalbe4
Copy link
Contributor

eyalbe4 commented Oct 13, 2016

@milosmns and all,
Version 1.7.2 with this fix has been released.

@milosmns
Copy link

@eyalbe4 Kewl, thanks! Here's a beer! 🍺

@iLucasLiu
Copy link

@eyalbe4 Thank U, Version 1.7.2 with this fix has been released! It's right!

@renatoathaydes
Copy link

The fix for this issue was wrong, it just fails to run the task silently now, which can cause a lot of pain when you think you've published your artifact but you didn't.

I don't understand why it is expected that a root project that has no configuration for the bintray plugin should allow the plugin to be applied on it without failing. Shouldn't everyone just configure the plugin in the sub-projects they actually use the plugin on?

If the concern is that the subProjects share some configuration, Gradle has many ways for sharing configuration, for example, from an external gradle file which the subprojects apply.

Sorry if I misunderstand this issue, but it looks to me that you just made the plugin task silently fail to fix this one particular case, without taking into consideration that it SHOULD fail in most other scenarios.

@eyalbe4
Copy link
Contributor

eyalbe4 commented Aug 4, 2018

@renatoathaydes,
I believe your comment refers to the original fix this issue discusses from almost two years ago.
The implementation since then has been changed and improved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants