Discussion:
Multi Project with Flat Directories, subproject not inheriting properties
richardm
2010-11-03 11:52:57 UTC
Permalink
I have a multi-project build with a flat layout as follows:

- main-build
build.gradle
settings.gradle
- ProjA
- ProjA1
- ProjA2
- ProjB

ProjA contains 2 other projects. Their is a single build file in the
main-build project. My sub-projects ProjA1 and ProjA2 aren't inheriting any
properties from ProjA. The example below shows a simple property being set
in ProjA. If I try to output this in ProjA1 I get an error 'Could not find
property 'propATest' on project ':projA/projA1''

I've tried setting the path with project(':projA:projA1') rather than
project(':projA/projA1'), but this doesn't work 'Project with path
':projA:projA1' could not be found in root project 'main-build'.

settings.gradle
includeFlat 'projA', 'projB', 'projA/projA1', 'projA/projA2'

build.gradle
apply plugin: 'java'

dependsOnChildren()

subprojects {
apply plugin: 'java'
}

project(':projA') {
propATest = "propATest"
println "projA Test = $propATest"
}

project(':projA/projA1') {
println "projA1 Test = $propATest"
}
--
View this message in context: http://gradle.1045684.n5.nabble.com/Multi-Project-with-Flat-Directories-subproject-not-inheriting-properties-tp3248301p3248301.html
Sent from the gradle-user mailing list archive at Nabble.com.
Adam Murdoch
2010-11-03 22:09:56 UTC
Permalink
Post by richardm
- main-build
build.gradle
settings.gradle
- ProjA
- ProjA1
- ProjA2
- ProjB
ProjA contains 2 other projects. Their is a single build file in the
main-build project. My sub-projects ProjA1 and ProjA2 aren't inheriting any
properties from ProjA. The example below shows a simple property being set
in ProjA. If I try to output this in ProjA1 I get an error 'Could not find
property 'propATest' on project ':projA/projA1''
I've tried setting the path with project(':projA:projA1') rather than
project(':projA/projA1'), but this doesn't work 'Project with path
':projA:projA1' could not be found in root project 'main-build'.
settings.gradle
includeFlat 'projA', 'projB', 'projA/projA1', 'projA/projA2'
includeFlat() creates a flat project structure. What you're asking for above is the following hierarchy:

root
+-- projA
+-- projA/projA1
+-- projA/projA2
+-- projB

That is, 'projA/projA1' is not a child of 'projA'. It sounds like you're after something more like this:

root
+-- projA
| +-- projA1
| +-- projA2
+-- projB

You need to do something like this in your settings script:

// Define the logical project structure
include 'projA', 'projA:projA1', 'projA:projA2', 'projB'

// Specify the project directory for each project
project(':projA').projectDir = new File(settingsDir, '../projA')
project(':projA:projA1').projectDir = new File(settingsDir, '../projA/projA1')
... and so on, you can probably write some code to automate this ...

The above leaves the projectDir for the root project as 'main-build'

Alternatively, you could do something like this in your settings script:

rootProject.projectDir = settingsDir.parentFile

include 'projA', 'projA:projA1', 'projA:projA2', 'projB'


--
Adam Murdoch
Gradle Developer
http://www.gradle.org
CTO, Gradle Inc. - Gradle Training, Support, Consulting
http://www.gradle.biz
richardm
2010-11-04 11:39:46 UTC
Permalink
Thanks, your first suggestion worked! I thought you had to use includeFlat
if your build file wasn't at the root level above all the projects.
--
View this message in context: http://gradle.1045684.n5.nabble.com/Multi-Project-with-Flat-Directories-subproject-not-inheriting-properties-tp3248301p3249886.html
Sent from the gradle-user mailing list archive at Nabble.com.
richardm
2010-12-10 10:14:38 UTC
Permalink
Post by Adam Murdoch
root
+-- projA
| +-- projA1
| +-- projA2
+-- projB
// Define the logical project structure
include 'projA', 'projA:projA1', 'projA:projA2', 'projB'
// Specify the project directory for each project
project(':projA').projectDir = new File(settingsDir, '../projA')
project(':projA:projA1').projectDir = new File(settingsDir,
'../projA/projA1')
I've got my multi-project build setup as suggested above. I'm trying to add
repositories and dependencies into my projects. I have a lib directory in
projA that all the projects below need a compile dependency on. At the
moment I've got the compile depencies set in each sub-project e.g.

project (':projA:projA1l') {
dependencies.compile fileTree(dir: "$rootDir/../projA/lib", include:
'*.jar')
}

I'm trying to update the build to use repositories and more specific
depdencies e.g.

project(':projA') {
repositories {
flatDir(name: 'projA-lib', dirs: "$rootDir/../projA/lib")
}

project (':projA:projA1l') {
dependencies.compile ":log4j"
}

This isn't working, I get an 'unresolved dependencies' error in projA1.
From the error message I can see it's not even looking in the repository
'projA-lib' when attempting to resolve the dependency? As projA is a parent
of projA1 I thought it would look in the same repository. I don't want to
declare the repository in the 'subprojects' section as I have other top
level projects which shouldn't use this lib directory (e.g. projB in the
example above).

Do I need to declare the repository in all child projects?
--
View this message in context: http://gradle.1045684.n5.nabble.com/Multi-Project-with-Flat-Directories-subproject-not-inheriting-properties-tp3248301p3300035.html
Sent from the gradle-user mailing list archive at Nabble.com.
Loading...