Root project directory name breaks build with "configuration is is not declared in the module descriptor"


#1

I found a really strange bug/feature. I found that a working build can be broken by changing the project root directory name. Here is some code to reproduce the bug. NOTE, you must reproduce the directory/file names exactly.

~/proj/build.gradle

apply plugin:'base'
allprojects { group 'company.com'; version '1.0' }
configurations.create 'dist'
dependencies { dist project( path:':proj', configuration:'custom') }
task distribution( type:Zip) { from configurations.dist }

~/proj/proj/build.gradle

apply plugin:'base'
configurations.create 'custom'
task distribution( type:Zip) {
   from ('.') { include '*.*' }
}
artifacts { custom
distribution }

~/settings.gradle

include ( 'proj')

if you build the project, you will get the following error:

Configuration on demand is an incubating feature.  :proj:clean  :proj:distribution  :distribution

FAILURE: Build failed with an exception.

  • What went wrong: Could not resolve all dependencies for configuration ‘:dist’. > Module version company.com:proj:1.0, configuration ‘dist’ declares a dependency on configuration ‘custom’ which is not declared in the module descriptor for company.com:proj:1.0

  • 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: 0.962 secs

Investigation

The root poject dir name is ‘~/proj’. This conflicts with the defined subproject with the same name ‘~/proj/proj’. I think this is a bug, but maybe there is some valid reason why gradle is getting confused.

Workarounds 1. Rename ‘~/proj’ to something else, OR 2. Remove the ‘allprojects’ define, OR 3. Rename the ‘allprojects’ define, to ‘suprojects’, OR 4. Set the root project name in the ‘settings.gradle’ file

rootProject.name = 'customProject'