How to specify Gradle wrapper with Jenkins JobDSL? - jenkins-job-dsl

The JobDSL spec currently has:
job {
steps {
gradle('build')
}
}
but that creates a job that errors with:
FATAL: Unable to find Gradle Wrapper
How does one specify the Gradle wrapper to use? I don't see it documented in https://github.com/jenkinsci/job-dsl-plugin/wiki/Job-reference#gradle.

It's not a standard thing to do, you have to escape out to a configure block:
job {
steps {
gradle('clean build', '--info --refresh-dependencies', true) {
it / wrapperScript('$NEBULA_HOME/gradlew')
}
}
}

Related

How to run tests in androidTest module?

In my build.gralde.kts there is a module description
val androidTest by getting {
dependencies {
implementation(kotlin("test-junit"))
implementation(AndroidTestDependencies.junit)
}
}
but in the project hierarchy it looks different than commonTest/commonMain etc. Besides, for some reason I can't run the test in this module. What could be the problem?
Can you try to set junit dependency like this:
val androidTest by getting {
dependencies {
implementation(kotlin("test-junit"))
implementation("junit:junit:4.13.2")
}
}
In my case it works fine

Jenkins Pipeline not execute my UnitTests.exe

I am doing a jenkins pipeline with different stages.
I stuck now at executing my unit-tests after build
This is my pipeline (it is shorted)
stage('Build') {
steps {
dir('UnitTests') {
bat 'make TEST_FOLDER=UnitTestFiles all'
}
}
}
stage('Run Unit-Tests') {
steps {
dir('UnitTests') {
bat 'UnitTests.exe --gtest_output=xml:UnitTestReport.xml'
}
}
}
-> Build is done successfully, I can see UnitTests.exe in the workspace, but
-> Jenkins is not running UnitTests.exe.
Why?

How to create separate tests with Gradle and Kotlin?

I am working on a Kotlin project with Gradle that includes unit tests. I want to add some integration tests (or functional tests, never understood the difference between the two), but I want to be able to run them independently. Ideally, the source of the tests are in different folders.
I am using Gradle 4.5 and my build.gradle file looks something like this :
buildscript {
ext.kotlin_version = '1.2.21'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin'
apply plugin: 'application'
mainClassName = 'xyz.bobdudan.myproject.AppKt'
repositories {
maven { url "http://maven.stardog.com" }
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
testCompile 'io.kotlintest:kotlintest:2.0.7'
}
I have tried the method described here for java, but it doesn't work : the task also runs the unit tests, but they can't be found, and the integration tests are not executed at all.
What can i do ?
Edit :
Here is the result of gradle clean integTest with the solution of #lance-java:
:clean
:compileIntegTestKotlin
:compileIntegTestJava NO-SOURCE
:processIntegTestResources NO-SOURCE
:integTestClasses UP-TO-DATE
:integTest NO-SOURCE
Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
See https://docs.gradle.org/4.5/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 1s
2 actionable tasks: 2 executed
So nothing is executed (I make sure that the tests are supposed to fail)
Note: I'm not a kotlin dev so will write in groovy.
You can add another SourceSet which will automatically add a JavaCompile task for the SourceSet and also a few Configuration instances to the model (eg integTestCompile, integTestCompileOnly, integTestRuntime etc)
sourceSets {
integTest {
java.srcDir 'src/integTest/java'
resources.srcDir 'src/integTest/resources'
}
}
configurations {
integTestCompile.extendsFrom compile
}
Then you can add another Test task
task integTest(type: Test) {
testClassesDir = sourceSets.integTest.output.classesDir
classpath = sourceSets.integTest.runtimeClasspath
}
You may wish to wire the integTest task into the normal DAG, or perhaps you'll leave this off and call it explicitly
check.dependsOn integTest
To tell long story short you have to:
create separate source sets,
create testTask for each test source,
set it up,
define order these tasks should be executed during build/check
and you are good to go.
Here is a guide in an answer to another question about how to do this for project using JUnit5 and Kotlin Spek test framework.

Sonarqube task in Gradle does not produce test coverage

I have multi-project Gradle script. I added to the root project:
buildscript {
repositories{
...
}
dependencies { classpath("org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.2.1") }
}
apply plugin: org.sonarqube.gradle.SonarQubePlugin
sonarqube {
properties {
property "sonar.junit.reportsPath", "$projectDir/build/test-results/test"
property "sonar.host.url", "http://localhost:9000"
property "sonar.verbose", "true"
}
}
Sonarqube shows the correct number of tests, but coverage is 0.
I use Gradle 3.0, Java 1.8.0_45, Sonarqube 6.1.
Gradle console shows many "Class not found" messages.
Gradle console also shows message:
"Reports path contains no files matching TEST-.*.xml :
myPath\build\test-results\test"
, which is correct, since that particular project does not have any tests.
In my child project, I have:
apply plugin: 'java'
apply plugin: "jacoco"
jacocoTestReport {
reports {
xml.enabled = true
}
}
check.dependsOn jacocoTestReport
Run Gradle task "sonarqube" of the root project.
No SonarQube Analyzer or plugin executes your tests or the coverage calculation for you. You must do those things before analysis and feed the resulting report(s) into your analysis.

How to run integration tests from IntelliJ context menu for gradle project?

Using IntelliJ IDEA 14.0.2, I have imported a gradle java project. We have set up a sourceSet and configuration to separate integration tests from unit tests. (our integration tests are in the test source tree, but in their own package). Relevant bits from the build.gradle are:
sourceSets {
test {
java {
exclude '**/it/**'
}
}
integTest {
java {
srcDir 'src/test/java'
include '**/it/**'
}
resources {
srcDir 'src/test/resources'
}
compileClasspath += sourceSets.main.output + sourceSets.test.output + configurations.testRuntime
runtimeClasspath += sourceSets.main.output + sourceSets.test.output + configurations.testRuntime
}
}
configurations {
integTestCompile.extendsFrom testCompile
integTestRuntime.extendsFrom testRuntime
}
idea {
module {
scopes.TEST.plus += [ configurations.integTestCompile ]
}
}
task integTest(type: Test) {
testClassesDir = sourceSets.integTest.output.classesDir
classpath = sourceSets.integTest.runtimeClasspath
}
This works fine from the command line. But when I open up the source of an integration test in IntelliJ and right-click to run it, IntelliJ launches the "test" task rather than the "integTest" task. How do I get IntelliJ to launch the correct task?
Alternatively, how can I make the test task delegate to another task based on the contents of the "--tests " arg?
Follow this: gradle settings > Gradle > Runner and check Delegate IDE build/run actions to gradle. Then apply and Ok.
Good luck!
Right-click on the test on file and you should see a menu option for Create Run Configuration >. Select that an in the dialog, modify the Tasks option. Change that to integTest and click OK. From that point, you might have to run the test using the menu system rather than the context system. i.e. Run > Run...
My solution is to configure IntelliJ to not use Gradle as a test runner, but to execute the tests with the built-in JUnit runner. This is just a configuration option in IntelliJ IDEA at the Gradle settings.
See https://www.jetbrains.com/help/idea/gradle-settings.html#gradle_tests for details.