[GRADLE-1591] Adding a projectProperty to the Sonar configuration removes all default projectProperties that are added by the Plugin's convention Created: 05/Jun/11  Updated: 04/Jan/13  Resolved: 08/Jun/11

Status: Resolved
Project: Gradle
Affects Version/s: 1.0-milestone-3
Fix Version/s: None

Type: Bug
Reporter: Joshua Shrader Assignee: Unassigned
Resolution: Fixed Votes: 0


 Description   

The sonar plugin defines a number of default project properties:
sonarTask.conventionMapping.projectProperties =

{ ["sonar.java.source": project.sourceCompatibility as String, "sonar.java.target": project.targetCompatibility as String, "sonar.dynamicAnalysis": "reuseReports", "sonar.surefire.reportsPath": project.test.testResultsDir as String] }

When projectProperty(String key, String value) or projectProperties(Map properties) is called on the Sonar plugin, the closure (above) never gets executed and thus the user is responsible for redefining all default properties.

The documentation states that the above methods "add the specified property(ies) to the map of project properties.



 Comments   
Comment by Joshua Shrader [ 05/Jun/11 ]

I was able to resolve this by adding an admittedly non-elegant line in the configureConventions() method of the SonarPlugin class:

sonarTask.projectProperties(sonarTask.projectProperties)

A unit test and fix have been added on my branch, and a pull request (#33) has been created.

I'm not completely familiar with the plugin convention paradigm. Please let me know if there is a more appropriate fix.

Comment by Joshua Shrader [ 06/Jun/11 ]

After some more digging, I came up with http://www.mail-archive.com/user@gradle.codehaus.org/msg08507.html, which states that convention mappings don't play well with collections. That seems to be the problem here. Perhaps this issue will get resolved when the kinks are worked out of the convention mappings. I'd be happy to help if I can.

Comment by Szczepan Faber [ 06/Jun/11 ]

Hey,

I tried to outline the mechanics of convention properties here: http://www.gradle.org/releases/latest/docs/dsl/org.gradle.api.dsl.ConventionProperty.html

You've basically hit the limitation of the DSL. As a workaround you can do the following:

sonarTask.projectProperties += [ "some.prop" : "some.value"]

It's not perfect, because it will make the convention property's closure evaluate early and hence it will became sensitive to the evaluation order of your build. However, I don't think it's going to be a problem in your build because you probably don't configure sourceCompatibility or testResultsDir at the bottom of your gradle build, right?

Fixing this limitation is high on our list, believe me

I'll make comments separately on your pull request.

Comment by Szczepan Faber [ 06/Jun/11 ]

mistake, should not be closed

Comment by Szczepan Faber [ 08/Jun/11 ]

Merged. Thanks for the contribution!!!

Generated at Wed Jun 30 11:59:26 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.