Hello!
I have started implementing Gradle build scripts for our company purposes, but I met some obstacles.
Problem is with variable project.name. In Gradle it is calculated from project directory. But unfortunately when Sonar is started on TeamCity CI server this name is just a garbage (it’s some kind of hash e.g. 1eefa89ab698a6dc). Normally a lot of different logic depends on project.name. In my case it is e.g. jar name, Sonar ‘key’ and ‘name’ properties, distribution name. It’s not necessary to say that when project is in such a strange named directory all of these tasks will produce also garbage. To make it worse you can NOT change project.name variable - it is immutable(*).
To fix this problem I am trying to use extension properties. But without success… I have my build script in two files: build.gradle and common.gradle. My project configuration should be located in build.gradle and common part in second file.
When I put: ext.name = ‘hpa-core’ in build.gradle
I can see this property in common.gradle here: task mytest {
println project.ext.name }
but I can not see it in sonar configuration: sonar {
project {
name = “${project.ext.name}-gradle”
key = “${project.ext.name}”
version = “continuous-integration”
} }
Script is not executed because of “cannot get property ‘name’ on extra properties extension as it does not exist” error in: name = “${project.ext.name}-gradle”
How to overcome this problem?
BR Marcin
(*) I think that immutability of project.name is causing a lot of troubles. It should be possible to just override project.name with user supplied name. In general it is wrong assumption that project name is strictly connected with project directory. In my case CI server is naming directories in some random way. Also developers can have multiple directories with different versions of project in different directories. Maybe it is good default, but it should be possible to override it.