How to set conditional Gradle properties?

How do I set task properties in a Gradle Plugin

  • I am creating a gradle plugin to apply the sonar-runner plugin and default many of the values such as the sonar host URL and the sonar JDBC URL. I cannot figure out how to set the properties though. When I set this up in build.gradle I use: apply plugin: 'sonar-runner' sonarRunner { sonarProperties { property 'sonar.host.url', 'http://mySonar.company.com' property 'sonar.jdbc.url', 'jdbc:mysql://127.0.0.1:1234/sonar' } } My gradle plugin looks like: class MySonarPlugin implements Plugin<Project> { @Override void apply(Project project) { project.apply plugin: 'sonar-runner' project.configurations { sonarRunner { sonarProperties { property 'sonar.host.url', 'http://mySonar.company.com' property 'sonar.jdbc.url', 'jdbc:mysql://127.0.0.1:1234/sonar' } } } } } With this setup I get a No signature of method exception. How should I be setting these properties?

  • Answer:

    I discovered that I could use project.getExtensions().sonarRunner.sonarProperties{ ... } to set the sonar properties. See example below. class MySonarPlugin implements Plugin<Project> { @Override void apply(Project project) { project.apply plugin:'sonar-runner' project.getExtensions().sonarRunner.sonarProperties { property 'sonar.host.url', 'http://mySonar.company.com' property 'sonar.jdbc.url', 'jdbc:mysql://127.0.0.1:1234/sonar' } } }

Mike Rylander at Stack Overflow Visit the source

Was this solution helpful to you?

Other answers

It should be: class MySonarPlugin implements Plugin<Project> { @Override void apply(Project project) { project.apply plugin: 'sonar-runner' project.sonnarRunner { sonarProperties { property 'sonar.host.url', 'http://mySonar.company.com' property 'sonar.jdbc.url', 'jdbc:mysql://127.0.0.1:1234/sonar' } } } } configurations is something completely different.

Opal

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.