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

Properties defined in 'gradle.properties' should be passed down to child builds #2534

Open
bigdaz opened this issue Jul 19, 2017 · 17 comments
Open
Labels
a:feature A new functionality in:build-environment Gradle, project, system and environment properties, CLI flags in:composite-builds including BuildIdentifier p:idiomatic

Comments

@bigdaz
Copy link
Member

bigdaz commented Jul 19, 2017

@oehme commented on Thu Oct 06 2016

Properties (both in gradle.properties and passed via -P) should be passed to included builds.


@adammurdoch commented on Wed Mar 08 2017

Maybe. The injection of configuration from a containing build needs more discussion. I don't think we necessarily want to automatically inherit everything, but probably want something a bit more declarative to allow a build to push config down.


@adammurdoch commented on Wed Mar 08 2017

As always, we should start with the use cases instead of the implementations.


@eskatos commented on Tue Apr 25 2017

One example use case. I wanted to run the :install task of the Gradle build from a composite build and pass it a installPath property. Ideally my composite build would have a bunch of tasks depending on :gradle:install with different installPath properties. Maybe it's a bit of a stretch.

@bigdaz bigdaz added a:feature A new functionality from:member in:composite-builds including BuildIdentifier labels Jul 19, 2017
@alexey-kanashevich
Copy link

Hello, Maybe there is workaround for this. Need to pass project property to root composite build and override it included projects.

@trevjonez
Copy link

another use case. composite builds for android project must all use the same version of the android gradle plugin. I usually setup my projects with agp_version=x.y.z in gradle.properties, but having to go update 2...N projects to test a new versions is less than ideal.

@bamboo bamboo self-assigned this Mar 2, 2020
@LarsKaulen
Copy link
Contributor

Properties passed via -P are already passed to included builds (tested with Gradle versions 6.4 and 6.5), properties set in gradle.properties are not passed.

I have another use case, for which it would be necessary to set a property programmatically. If projectA includes projectB and a certain task of projectA is executed, I want to set a property in the build.gradle of projectA that can be evaluated in the build.gradle of projectB, because in this case a special behaviour of projectB is necessary.

I guess this isn't possible/supported at the moment?

@Dkhusainov
Copy link

Dkhusainov commented Sep 23, 2020

Simple workaround for reading properties from root project into included project if anyone needs it:

buildscript {
  new BufferedReader(new FileReader(file('../gradle.properties'))).withCloseable { reader ->
    String line
    while ((line = reader.readLine()) != null) {
      if (line.startsWith('myProperty')) {
        project.ext.myProperty = line.substring(line.indexOf('=') + 1)
      }
    }
  }
}

@big-guy big-guy added this to the 6.8 RC1 milestone Oct 14, 2020
@jjohannes
Copy link
Contributor

jjohannes commented Oct 14, 2020

Common Use Case

I define the version of my product in gradle.properties and all my components, located in separate builds, should use that same version.

Real world occurrence in Spring Boot build. If you change the build into a composite hierarchy, this breaks.

To reproduce the issue:

  • download composite build sample
  • Add a gradle.properies files with version=1.1
  • Add a println(name + ":" + properties["version"]) to all build files

You'll see how it works for app (which is a subproject) but not the other included build projects:

number-utils:unspecified

string-utils:unspecified

multirepo-app:1.1

app:1.1

Expected Behavior

  • A property is passed down to child builds and from there to the nested children
  • A child may override the property in its own gradle.properties, then that value is used and passed to the children of that child
  • a -P property overrides all definition of that property in all gradle.properties files (this is already working today)

@jjohannes jjohannes changed the title Properties should be passed down into included builds Properties defined in 'gradle.properties' should be passed down to child builds Oct 14, 2020
@jjohannes jjohannes removed this from the 6.8 RC1 milestone Nov 10, 2020
@jjstreet
Copy link

jjstreet commented Mar 17, 2021

Another use case similar to @jjohannes and also related to spring boot is when I want to use conventions to author a multi-project build of a spring boot based project.

I have 2 main projects app and domain both are using spring's style of dependency management.

I have an application convention plugin that applies org.springframework.boot and because of that, have to provide the dependency in the build.gradle file:

dependencies {
    implementation "io.spring.gradle:dependency-management-plugin:$springDependencyManagementVersion"
    implementation "org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion"
}

I have to add springBootVersion to the buildSrc gradle.properties file instead of where I would like to see it--in the my root project's gradle.properties where other versions are held as properties.

I also have to set things other properties like urls to my nexus repos in each properties file as well because they are not inherited from the root project.

I would be happy with what @jjohannes is proposing as expected behavior.

Does gradle know the full project hierarchy so that included composite builds know what project is the parent?

@sugarmanz
Copy link

sugarmanz commented Nov 25, 2021

Just wanted to post the workaround that ended up working best for me. If there is no need to define additional properties at the included composite build, you can just symlink the top-level project gradle.properties into the composite project. This will ensure that the properties are automatically propagated for use within the composite project as "regularly" defined properties.

EDIT:
Just to note that this falls short if you'd like to build the project on different operating systems.

@Phlegethon90
Copy link

Any fix in sight?

@programadorthi
Copy link

Sharing my workaround to this. It is not the better approach but works:

Tree:

- root-project
  - build-logic
  - domain-model
  - platforms
  - ...
  - gradle.properties
  - settings.gradle.kts

settings.gradle.kts

val builds = listOf(
    "build-logic",
    "domain-model",
    "platforms",
)

rootProject.name = "root-project"

// Issue: https://github.com/gradle/gradle/issues/2534
val gradleProperties = "gradle.properties"
builds.forEach { projectName ->
    includeBuild(projectName)

    val includeGradleProperties = File(rootDir, "$projectName/$gradleProperties")
    if (!includeGradleProperties.exists()) {
        file(gradleProperties).copyTo(includeGradleProperties)
    }
}

.gitignore

/**/gradle.properties

@Cyberavater
Copy link

Cyberavater commented Mar 30, 2024

Common Use Case

I define the version of my product in gradle.properties and all my components, located in separate builds, should use that same version.

Real world occurrence in Spring Boot build. If you change the build into a composite hierarchy, this breaks.

To reproduce the issue:

  • download composite build sample
  • Add a gradle.properies files with version=1.1
  • Add a println(name + ":" + properties["version"]) to all build files

You'll see how it works for app (which is a subproject) but not the other included build projects:

number-utils:unspecified

string-utils:unspecified

multirepo-app:1.1

app:1.1

Expected Behavior

  • A property is passed down to child builds and from there to the nested children
  • A child may override the property in its own gradle.properties, then that value is used and passed to the children of that child
  • a -P property overrides all definition of that property in all gradle.properties files (this is already working today)

Can composite builds now share a single gradle.properties?

@lonkly
Copy link

lonkly commented Apr 23, 2024

@Cyberavater they just intentionally won't add this behavior by default

@technoir42
Copy link

A simple workaround I'm using is symlinking gradle.properties file into all included builds using relative paths.

@lonkly
Copy link

lonkly commented Apr 25, 2024

A simple workaround I'm using is symlinking gradle.properties file into all included builds using relative paths.

Will you kindly let us see the script? 😜

@technoir42
Copy link

Will you kindly let us see the script? 😜

There is no script. Creating a symlink is as simple as:

cd my-included-build
ln -s ../gradle.properties

@rsicarelli
Copy link

A simple workaround I'm using is symlinking gradle.properties file into all included builds using relative paths.

It's a great solution if the whole team works on MacOS. Unfortunately, this is not possible for Windows users 😢 .

@bddckr
Copy link

bddckr commented May 2, 2024

I've used symlinks for gradle.properties successfully on Windows and can confirm it works when you got it configured before you clone the repo: https://github.com/git-for-windows/git/wiki/Symbolic-Links

@cmoine
Copy link

cmoine commented Jun 17, 2024

To import all properties (based on @Dkhusainov suggestion), I changed it to:

buildscript {
  Properties properties = new Properties()
  file('../gradle.properties').withInputStream {
    properties.load(it)
  }
  properties.forEach { key, val ->
    project.ext[key] = val
  }
}

my 2 cts 😉

@bamboo bamboo added the 👋 team-triage Issues that need to be triaged by a specific team label Oct 16, 2024
@mlopatkin mlopatkin removed the 👋 team-triage Issues that need to be triaged by a specific team label Oct 22, 2024
@ov7a ov7a added the in:build-environment Gradle, project, system and environment properties, CLI flags label Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:feature A new functionality in:build-environment Gradle, project, system and environment properties, CLI flags in:composite-builds including BuildIdentifier p:idiomatic
Projects
None yet
Development

No branches or pull requests