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

Allow injection of dependency versions from command line for central declaration of dependencies #17251

Open
ZakTaccardi opened this issue May 22, 2021 · 4 comments

Comments

@ZakTaccardi
Copy link

Central declaration of dependencies is an awesome feature! However, we have the need to inject different values via local.properties/gradle.properties/command line

Will custom dependency versions be injectable via gradle properties/local.properties?

No, this is out of scope of this version. We are thinking about standard ways to do it, to address the use case of testing a new version of a library.

#15352 (comment)

We currently have something like:

// gradle.properties
ANDROID_GRADLE_PLUGIN=4.1.2

But AGP released a new version! So I would like to test it via

// local.properties
ANDROID_GRADLE_PLUGIN=4.1.2

or command line (more useful for CI):

./gradlew app:assemble -PANDROID_GRADLE_PLUGIN=4.2.1

We would like to see both these use cases supported officially with the Central Declaration of Dependencies.

@ZakTaccardi ZakTaccardi added a:feature A new functionality to-triage labels May 22, 2021
@ZakTaccardi
Copy link
Author

ZakTaccardi commented May 22, 2021

I think because .toml values can be overridden (let me know if I'm incorrect here), we could do something like the following:

from(files("../gradle/libs.versions.toml"))
from(files("../gradle/libs.local-versions.toml"))

And the libs.local-versions.toml would override the duplicate values from libs.versions.toml.

So the local.properties concept is already supported, if I understand correctly. However, it would be great to support from the command line too

@JavierSegoviaCordoba
Copy link
Contributor

JavierSegoviaCordoba commented May 22, 2021

I am currently doing this:

// gradle.properties

javierscGradlePlugins=0.1.0-alpha.30
// buildSrc/settings.gradle.kts

val input = FileInputStream(file("../gradle.properties"))
val properties = Properties().apply { load(input) }
input.close()

val javierscGradlePlugins: String = properties.getProperty("javierscGradlePlugins")

dependencyResolutionManagement {
    repositories {
        mavenCentral()
    }

    versionCatalogs {
        create("pluginLibs") {
            from(files("../plugins-catalog/build/catalogs/libs.versions.toml"))
            version("javierscGradlePlugins", javierscGradlePlugins)
        }
    }
}

In my case I am not overriding it via CLI, but `./gradlew build -P"javierscGradlePlugins"="0.1.0-alpha.29" should work.

In the root settings.gradle.kts file in another project, I am using it without problems too, but the setup is simpler using by settings

// gradle.properties

massiveCatalogs=0.1.0-alpha.29
// settings.gradle.kts

dependencyResolutionManagement {
    repositories {
        mavenCentral()
        google()
        gradlePluginPortal()
    }

    versionCatalogs {
        val massiveCatalogs: String by settings

        create("libs") { from("com.javiersc.massive-catalogs:libs-catalog:$massiveCatalogs") }

        create("pluginLibs") {
            from("com.javiersc.massive-catalogs:plugins-catalog:$massiveCatalogs")
        }
    }
}

EDIT: well I am using it for settings the version of the catalog itself, not a version inside it, but I could use the version function to override a version as I used in buildSrc/settings.gradle.kts but just with by settings.

@stale
Copy link

stale bot commented Jun 12, 2022

This issue has been automatically marked as stale because it has not had recent activity. Given the limited bandwidth of the team, it will be automatically closed if no further activity occurs. If you're interested in how we try to keep the backlog in a healthy state, please read our blog post on how we refine our backlog. If you feel this is something you could contribute, please have a look at our Contributor Guide. Thank you for your contribution.

@stale stale bot added the stale label Jun 12, 2022
@gildor
Copy link
Contributor

gildor commented Jun 13, 2022

How can we prevent this feature from being closed?

I think the easiest solution is to have some convention for this, like for gradle properties, something like GRADLE_VERSION_CATALOG_$catalogName_$versionName

It's pretty common requirement, when we want to run tests on CI with updated version of some library

ajoberstar added a commit to clojurephant/clojurephant that referenced this issue Jul 30, 2022
Editor integrations, such as Cider and Calva (maybe others), rely on
being able to inject dependencies when starting nREPL in order to ensure
they have all of the capabilities their editors use.

Eventually, this could be supported natively by Gradle via [1], but this
has been a long-nagging issue with Gradle that made for a poorer user
experience than Leiningen, Boot, tools.deps, etc.

Since this is just a Gradle property, it can be provided by editors even
if the project isn't using Clojurephant (or the right version of
Clojurephant), meaning a graceful degradation to the old experience of
requiring the user to have put the right deps on the nREPL classpath.

[1] gradle/gradle#17251
ajoberstar added a commit to clojurephant/clojurephant that referenced this issue Jul 30, 2022
Editor integrations, such as Cider and Calva (maybe others), rely on
being able to inject dependencies when starting nREPL in order to ensure
they have all of the capabilities their editors use.

Eventually, this could be supported natively by Gradle via [1], but this
has been a long-nagging issue with Gradle that made for a poorer user
experience than Leiningen, Boot, tools.deps, etc.

Since this is just a Gradle property, it can be provided by editors even
if the project isn't using Clojurephant (or the right version of
Clojurephant), meaning a graceful degradation to the old experience of
requiring the user to have put the right deps on the nREPL classpath.

[1] gradle/gradle#17251

This fixes Clojurephant's side of #78.
ajoberstar added a commit to clojurephant/clojurephant that referenced this issue Jul 30, 2022
Editor integrations, such as Cider and Calva (maybe others), rely on
being able to inject dependencies when starting nREPL in order to ensure
they have all of the capabilities their editors use.

Eventually, this could be supported natively by Gradle via [1], but this
has been a long-nagging issue with Gradle that made for a poorer user
experience than Leiningen, Boot, tools.deps, etc.

Since this is just a Gradle property, it can be provided by editors even
if the project isn't using Clojurephant (or the right version of
Clojurephant), meaning a graceful degradation to the old experience of
requiring the user to have put the right deps on the nREPL classpath.

[1] gradle/gradle#17251

This fixes Clojurephant's side of #78.
@github-actions github-actions bot removed the stale label Sep 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants