Skip to content
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

Multi-project with version variables in root does not update #43

Closed
tony-schellenberg opened this issue Sep 3, 2020 · 9 comments
Closed
Labels
help wanted Extra attention is needed

Comments

@tony-schellenberg
Copy link
Contributor

When I use a version variable defined in the root project in a sub project, it does not update the root project variable. It updates the dependency used in the root project but not the one that is used in the sub project. Please let me know if more information is required and I'll do my best to provide it.

Gradle Version: 6.3
Gradle Versions Plugin: 0.29.0
Use Latest Version: 0.2.14

Project structure:

  • ./build.gradle -> root project
  • ./commonDependencies.gradle -> has an ext block with variables for versions
  • ./components/main/build.gradle -> subproject, only has a dependencies block on one of the libraries

All versions numbers are set in an ext block in commonDependencies.gradle as part of the root project as variables. There are only two dependencies/version variables defined. One dependency is referenced in each of the build.gradle files. I.e. one dependency is referenced in the root project and the other one is in the sub project.

In the root build.gradle, I've included the plugins in an allprojects stanza.

I've tried the following but haven't found a way to get the updates working:

  1. useLatestVersions
  2. useLatestVersions with --update-root-properties
  3. useLatestVersions with updateRootProperties = true
build.gradle
buildscript {
    repositories {
        jcenter()
    }
}

plugins {
    id 'com.github.ben-manes.versions' version '0.29.0'
    id 'se.patrikerdes.use-latest-versions' version '0.2.14'
}

wrapper {
    gradleVersion = '6.3'
}

def isNonStable = { String version ->
    def stableKeyword = ['RELEASE', 'FINAL', 'GA'].any { it -> version.toUpperCase().contains(it) }
    def regex = /^[0-9,.v-]+(-r)?$/
    return !stableKeyword && !(version ==~ regex)
}

allprojects {
    apply plugin: 'java'
    apply from: "$rootDir/commonDependencies.gradle"

    apply plugin: 'com.github.ben-manes.versions'
    apply plugin: 'se.patrikerdes.use-latest-versions'

    // Change how the report for dependency updates is created to only include stable versions
    tasks.named('dependencyUpdates').configure() {
        rejectVersionIf {
            isNonStable(it.candidate.version)
        }
    }
    useLatestVersions {
       updateWhitelist = []
       updateBlacklist = []
       updateRootProperties = true
    }
}
commonDependencies.gradle
ext {
    junitJupiterVersion = '5.6.2'
    metricsVersion = '4.1.5'
}

repositories {
    jcenter()
}

dependencies {
    testImplementation "org.junit.jupiter:junit-jupiter-api:$junitJupiterVersion"
}
settings.gradle
include 'main'
project(':main').projectDir = new File(rootDir, 'components/main')

getRootProject().setName('demo')
components/main/build.gradle
dependencies {
    implementation "io.dropwizard.metrics:metrics-core:$metricsVersion"
}
@patrikerdes patrikerdes added the help wanted Extra attention is needed label Sep 5, 2020
@asodja
Copy link
Contributor

asodja commented Sep 15, 2020

Currently --update-root-properties works only for gradle.properties. One would have to extend this functionality, to also update other files. I can give some guidance on how it works:

  1. UseLatestVersionsTask finds all variables for every project, updates them, updates project files and writes variables into $project.buildDir/useLatestVersions/version-variables.json
  2. InternalAggregateRootTask then reads all useLatestVersions/version-variables.json and writes them to gradle.properties.

So one would probably just have to extend 2. to also write variables into other files.

@tony-schellenberg
Copy link
Contributor Author

Based on your comments, I went back and tried moving the version variables into gradle.properties and that seems to work as expected. I think that's probably a reasonable resolution so I'm going to close the ticket.

Thanks for the help.

@tony-schellenberg
Copy link
Contributor Author

I'd like to see if I can update the behaviour based on your comments above. I've had a look at the code and think I have an idea what to do.

Are there any developer guidelines or expectations for contributing? (e.g. should I be forking and creating a PR from there, would you prefer if I create a branch in this repo, etc)

@asodja
Copy link
Contributor

asodja commented Sep 17, 2020

I am actually not a maintainer, I just contributed a feature for updating root gradle.properties. Imo the best way is to create a fork, add your functionality + tests and then when you are happy with it you make a PR.

@patrikerdes
Copy link
Owner

Hi, I'm the (passive) maintainer, what @asodja said sounds good to me.

@tony-schellenberg
Copy link
Contributor Author

I've just started looking into this and I'm hoping someone can provide some insight or suggestions. I'm seeing a number of failing unit tests on an unmodified master branch. My dev system is Linux based and I've tried with both Java 8 and Java 11 with the same results.

Any thoughts or suggestions on why the tests might be failing on a clean repo?

@asodja
Copy link
Contributor

asodja commented Sep 17, 2020

As I remember there are some tests that actually do real updates. There is a class CurrentVersions with latest versions of some libraries, that has to be updated.

public static final String VERSIONS = '0.28.0' -> `com.github.ben-manes.versions` current version is 0.33.0, needs Update
public static final String JUNIT = '4.13' ->  `junit:junit` current version is 4.13, looks OK 
public static final String JUNIT_DEPS = '4.11' -> `junit:junit-dep` current version is 4.11, looks OK 
public static final String LOG4J = '1.2.17' -> `log4j:log4j` current version is 1.2.17, looks OK

@patrikerdes
Copy link
Owner

@asodja Thanks, you are correct

@tony-schellenberg I have updated the verions on the master branch, it shouldn't fail anymore

@tony-schellenberg
Copy link
Contributor Author

Yeah, that was the main issue. It appears there's a few tests that don't work as well and adding something like TRAVIS=true got me to a clean build.

Thanks for all the help on that.

tony-schellenberg added a commit to PasonSystems/gradle-use-latest-versions-plugin that referenced this issue Sep 18, 2020
 * Supports *.gradle files in the root project now
tony-schellenberg added a commit to PasonSystems/gradle-use-latest-versions-plugin that referenced this issue Sep 18, 2020
 * Addressing CodeNarc issues
tony-schellenberg added a commit to PasonSystems/gradle-use-latest-versions-plugin that referenced this issue Sep 21, 2020
 * Should be backwards comaptible
 * Defaults to `gradle.properties`
 * `build.gradle` is not allowed and generates an error
 ** Trying to set `build.gradle` affects plugin and other updates
tony-schellenberg added a commit to PasonSystems/gradle-use-latest-versions-plugin that referenced this issue Sep 21, 2020
 * Should be backwards comaptible
 * Defaults to `gradle.properties`
 * `build.gradle` is not allowed and generates an error
 ** Trying to set `build.gradle` affects plugin and other updates
patrikerdes added a commit that referenced this issue Sep 23, 2020
Fixes #43 Adding list of root files with variables to update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants