Gradle Tooling : How to set environment variable - gradle

I have a custom plugin and I am writing tests to test it. For this I'm using gradle tooling api (I found that to be the recommended way to test).
One of the test requires me to run a task by setting some environment variable. How do I test this. I do not see ProjectConnection providing a way to set environment variable.
If I have to manually test I would have to do this :
setenv LRG_REPOS foo
gradle verify_lrg -PlrgName=abc
where verify_lrg is task added by my custom plugin.
Currently to solve this, I am running using ProcessBuilder, but would like to know if there is any gradle tooling way (because all other tests are using gradle tooling api)

It will be possible to configure environment variables via gradle tooling api since 3.5 version, see details at https://github.com/gradle/gradle/pull/1029
https://github.com/gradle/gradle/blob/446468213543e32a0ce1bce0bbedabcfe925c572/subprojects/tooling-api/src/main/java/org/gradle/tooling/LongRunningOperation.java#L190

Related

How to set org.gradle.native system property when using the wrapper

I would like to set the org.gradle.native JVM system property to false to disable gradle native integration on our CI system where the OS version does not support it. I have no control over the OS. We use the gradle wrapper which invokes the gradle daemon to do the build.
The relevant gradle code that reads the property is here. Note that it's a static initialiser - it happens early - this may or may not be relevant. I have tried, without success:
./gradlew -Dorg.gradle.native=false
./gradlew -Dorg.gradle.jvmargs='-Dorg.gradle.native=false'
and also adding to $GRADLE_USER_HOME/gradle.properties:
systemProp.org.gradle.native=false

How to build a ci / cd pipeline with hybris commerce?

I am developing a pipeline for hybris.
I have doubts in the execution of the tests.
I'm following this tutorial:
https://clutcher.github.io/post/hybris/improve_hybris_test_run/
However, I have several extensions in customizing hybris.
Do I have to configure the buildcallbacks.xml file for each extension?
Is there any way to run the ant ci for all extensions?
For a first version I would use the following ant tasks:
integrationtests
performancetests
manualtests
bugprooftests
localizationtest
typecodetest
alltests
allwebtests
Make sure to mark your tests with the #IntegrationTest or #UnitTest annotation so that the ant task will find them.
You can filter the tests by:
extensions using the parameter -Dtestclasses.extensions=myextension
packages using the parameter -Dtestclasses.packages=my.package
excluded packages using the parameter -Dtestclasses.packages.excluded
For more information consider:
https://help.sap.com/viewer/d0224eca81e249cb821f2cdf45a82ace/2005/en-US/f7f454a4f5254944a366db9bdf129be6.html

Configure Multiple SonarQube Instances in a Gradle Build

In our CI environment, we currently have one build server (based on Atlassian Bamboo) and two SonarQube instances (versions 6.0 and 6.5). Initially, our CI server was configured to communicate with the 6.0 SonarQube instance. This has been configured in the /home/bamboo/.gradle/gradle.properties file on our CI server like this:
systemProp.sonar.host.url=<http url of SonarQube 6.0 instance>
systemProp.sonar.login=<username here>
systemProp.sonar.password=<password here>
Now we have another Gradle-based project running on our CI server which shall talk to the new SonarQube 6.5 instance. I tried configuring this but failed all the time.
Things I have done so far:
Added commandline arguments to gradle wrapper command:
I have tried adding -Dsonar.host.url=, -Dsonar.login=, -Dsonar.password= to the Gradle command. As this didn't seem to work, I have also tried to set commandline arguments as SonarQube system properties using -DsystemProp.sonar.host.url=, -DsystemProp.sonar.login=, -DsystemProp.sonar.password=. This didn't work either.
Added properties to the build.gradle file
- Added properties to the build.gradle file like this:
sonarqube {
properties {
property "sonar.host.url", "<http url of SonarQube 6.0 instance>"
property "sonar.login", "<username here>"
property "sonar.password", "<password here>"
...<other SonarQube analysis settings here>...
}
}
In all cases, the CI server talked to the wrong SonarQube instance (6.0). My question is, whether it is possible to configure a single project to talk to another SonarQube instance. As you have seen, we use Gradle 3.2.1 as a build tool. And we are using the org.sonarqube Gradle plugin too.
Thank you for any help.
André
Your first try did not work, because you set the system properties from the commandline, but setting it from the project properties later on resets the system properties to the configured values.
Your second try did not work, because the systemProp.sonar.login syntax is only suppored in gradle.properties files, not via -P commandline project properties.
Your third try did not work because the SonarQube scanner prefers the system property values over the value configured via the DSL, so that one can change what is configured in the build script with the help of local configuration.
You need to set the system properties in your build script manually, this then overwrite what was automatically set from the project property. Using the project gradle.properties file does not work as the user file overwrite the project file. So you need something like System.properties.'sonar.login' = '...' in your build script. You can either hard-code it there, or then use project properties that you can set in your gradle.properties file or via -P parameters.
Besides that, I'd never depend on having any configuration in Gradle User dir on a build server. Most buildservers use build agents that might run on distributed machines, so you would always have to make sure that all build agents are configured the same and so on. I'd always configure in the build setup of the build server the according configuration, either by setting system properties, or environment properties or commandline arguments.
Just my 2ct.

How can I set gradle project properties when using gradle tooling API?

I'm trying to use the tooling API to run a gradle task from groovy code. The following works:
ProjectConnection connection = GradleConnector.newConnector()
.forProjectDirectory(new File(System.properties.getProperty('user.dir')))
.connect()
connection.newBuild()
.forTasks('deploy')
.setStandardOutput(System.out)
.run()
But the task I want to run depends on project properties. For example, if I was running it from the command line, I'd use
gradle -Penv=local deploy
I can't figure out how, using the tooling API, to set those project values.
You can do:
connection.newBuild()
.withArguments('-Penv=local')
.forTasks('deploy')
.setStandardOutput(System.out)
.run()

Makefile to gradle conversion for golang application

I have a go lang application which exposes a rest API and logs the information to DB. I am trying to convert the make file to gradle build. Is there any default way similar to maven2gradle plugin or the gradle build file should be written manually? I checked the syntactical differences between gradle and make file but still not clear about passing run time arguments to gradle that is similar to
run:build
./hello -conf=/apps/content/properties/prop.json -v=0 -logDest="FILE" -log_dir="/var/log/logdir"
hello is my executable and others are the runtime arguments. This is my first attempt in migrating make to gradle and I couldnt find any clear documentation. Please help.
As far as I have checked, there is no direct plugin that could do this task. As a workaround, the build execution could be written as seperate tasks in gradle and ordered accordingly. Tasks here would contain setting Go path, installing dependencies and building the application and would be run as command line process in Gradle. Gradle provides support to run command line processes as described in gradle documentation. Hope it helps.

Resources