[GRADLE-3086] Changing rootProject projectDir from settings.gradle does not work Created: 11/May/14  Updated: 15/Jul/14  Resolved: 15/Jul/14

Status: Resolved
Project: Gradle
Affects Version/s: None
Fix Version/s: 2.1-rc-1

Type: Bug
Reporter: Gradle Forums Assignee: Luke Daley
Resolution: Fixed Votes: 1


 Description   

The User Guide says that you can change the location of the root project from settings.gradle.
But I cannot get this working properly.
If I change ```rootProject.projectDir``` or ```project(':').projectDir``` in settings.gradle it seems to have no effect.
Furthermore, if I add subprojects, they are not not found if I tried to change ```rootProject.projectDir``` or ```project(':').projectDir``` in settings.gradle.



 Comments   
Comment by Gradle Forums [ 11/May/14 ]

Please give a minimal self-contained example and explain the desired vs. actual outcome (i.e. how do you tell that it doesn't work).

Comment by Gradle Forums [ 11/May/14 ]

Sure, here the example: [1]https://github.com/Vampire/change-roo...

Command: ```./gradlew test -c settings1.gradle && ./gradlew test -c settings2.gradle```

Actual oucome:

D:\cygwin\home\bkautler\testing
D:\cygwin\home\bkautler\testing\root\sub
:test
project ':sub'
:sub:test

BUILD SUCCESSFUL

Total time: 2.518 secs
D:\cygwin\home\bkautler\testing
:test

BUILD SUCCESSFUL

Total time: 2.474 secs

Expected oucome:

D:\cygwin\home\bkautler\testing
D:\cygwin\home\bkautler\testing\root\sub
:test
project ':sub'
:sub:test

BUILD SUCCESSFUL

Total time: 2.518 secs
D:\cygwin\home\bkautler\testing\root
D:\cygwin\home\bkautler\testing\root\sub
:test
project ':sub'
:sub:test

BUILD SUCCESSFUL

Total time: 2.474 secs

or

Command: ```./gradlew :test :sub:test -c settings1.gradle && ./gradlew :test :sub:test -c settings2.gradle```

Actual oucome:

D:\cygwin\home\bkautler\testing
D:\cygwin\home\bkautler\testing\root\sub
:test
project ':sub'
:sub:test

BUILD SUCCESSFUL

Total time: 2.76 secs
D:\cygwin\home\bkautler\testing

FAILURE: Build failed with an exception.

  • What went wrong:
    Project 'sub' not found in root project 'testing'.
  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 2.599 secs

Expected oucome:

D:\cygwin\home\bkautler\testing
D:\cygwin\home\bkautler\testing\root\sub
:test
project ':sub'
:sub:test

BUILD SUCCESSFUL

Total time: 2.76 secs
D:\cygwin\home\bkautler\testing\root
D:\cygwin\home\bkautler\testing\root\sub
:test
project ':sub'
:sub:test

BUILD SUCCESSFUL

Total time: 2.76 secs

*Note: The build.gradle next to the settingsX.gradle files is only there to have the test task working as the root project directory did not get changed. In the correctly working version it should not be present!*
----------------------------------------------------------------------------------------
[1] https://github.com/Vampire/change-root-project-dir-showcase

Comment by Björn Kautler [ 11/May/14 ]

While playing I found another edge case.
Probably related.
I added settings3.gradle to the showcase.
If you call the command with this file, you get the output

FAILURE: Build failed with an exception.

* What went wrong:
Could not select the default project for this build. No projects in this build have project directory 'D:\cygwin\home\bkautler\testing'.
> No projects in this build have project directory 'D:\cygwin\home\bkautler\testing'.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 2.219 secs
Comment by Björn Kautler [ 13/May/14 ]

Some more information.

I see now that settings3.gradle is working as expected as far as it gets, as it complains that the directory where I invoke gradle is not part of the build which is kind of correct as it is no project directory anymore but only the settings directory.

May I suggest to use the root project as default project in this case?

Adding -p root to the command line with settings3, resulting in ./gradlew :test :sub:test -c ./settings3.gradle -p root will yield again the same result as settings2.gradle, except that the root project is correctly the one from root, not from master, just the sub project is missing.

Furthermore, cd root && ../gradlew :test :sub:test -c ../settings2.gradle and ./gradlew :test :sub:test -c ./settings2.gradle -p root work correctly as I just found out.
So it just is broken if you call gradle from the settings dir as it seems.

Comment by Björn Kautler [ 13/May/14 ]

Here you have the culprit: https://github.com/gradle/gradle/blob/RB_1.11/subprojects/core/src/main/groovy/org/gradle/initialization/SettingsHandler.java#L55

Comment by Björn Kautler [ 14/May/14 ]

https://github.com/gradle/gradle/pull/277 should fix this issue.

Generated at Wed Jun 30 12:39:33 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.