Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle doesn't execute tests

when I run my gradle script it always does this:

> Configure project :
Evaluating root project 'trading-library' using build file 'C:\Users\xxx\Documents\Repositories\Trading_Library\Trading_Library\build.gradle'.
Invalidating in-memory cache of C:\Users\xxx\.gradle\caches\journal-1\file-access.bin
All projects evaluated.
Selected primary task 'cleanTest' from project :
Selected primary task 'test' from project :
Tasks to be executed: [task ':cleanTest', task ':compileJava', task ':processResources', task ':classes', task ':compileTestJava', task ':processTestResources', task ':testClasses', task ':test']
:cleanTest (Thread[Execution worker for ':',5,main]) started.

> Task :cleanTest UP-TO-DATE
Task ':cleanTest' is not up-to-date because:
  Task has not declared any outputs despite executing actions.
:cleanTest (Thread[Execution worker for ':',5,main]) completed. Took 0.002 secs.
:compileJava (Thread[Execution worker for ':',5,main]) started.

> Task :compileJava UP-TO-DATE
Skipping task ':compileJava' as it is up-to-date.
:compileJava (Thread[Execution worker for ':',5,main]) completed. Took 0.029 secs.
:processResources (Thread[Execution worker for ':',5,main]) started.

> Task :processResources NO-SOURCE
Skipping task ':processResources' as it has no source files and no previous output files.
:processResources (Thread[Execution worker for ':',5,main]) completed. Took 0.0 secs.
:classes (Thread[Execution worker for ':',5,main]) started.

> Task :classes UP-TO-DATE
Skipping task ':classes' as it has no actions.
:classes (Thread[Execution worker for ':',5,main]) completed. Took 0.0 secs.
:compileTestJava (Thread[Execution worker for ':',5,main]) started.

> Task :compileTestJava UP-TO-DATE
Skipping task ':compileTestJava' as it is up-to-date.
:compileTestJava (Thread[Execution worker for ':',5,main]) completed. Took 0.032 secs.
:processTestResources (Thread[Execution worker for ':',5,main]) started.

> Task :processTestResources NO-SOURCE
Skipping task ':processTestResources' as it has no source files and no previous output files.
:processTestResources (Thread[Execution worker for ':',5,main]) completed. Took 0.001 secs.
:testClasses (Thread[Execution worker for ':',5,main]) started.

> Task :testClasses UP-TO-DATE
Skipping task ':testClasses' as it has no actions.
:testClasses (Thread[Execution worker for ':',5,main]) completed. Took 0.0 secs.
:test (Thread[Execution worker for ':',5,main]) started.

> Task :test
Task ':test' is not up-to-date because:
  Output property 'binResultsDir' file C:\Users\xxx\Documents\Repositories\Trading_Library\Trading_Library\build\test-results\test\binary has been removed.
  Output property 'binResultsDir' file C:\Users\xxx\Documents\Repositories\Trading_Library\Trading_Library\build\test-results\test\binary\output.bin has been removed.
  Output property 'binResultsDir' file C:\Users\xxx\Documents\Repositories\Trading_Library\Trading_Library\build\test-results\test\binary\output.bin.idx has been removed.
Custom actions are attached to task ':test'.
Finished generating test XML results (0.0 secs) into: C:\Users\xxx\Documents\Repositories\Trading_Library\Trading_Library\build\test-results\test
Generating HTML test report...
Finished generating test html results (0.017 secs) into: C:\Users\xxx\Documents\Repositories\Trading_Library\Trading_Library\build\reports\tests\test
:test (Thread[Execution worker for ':',5,main]) completed. Took 0.367 secs.

This is the output after a gradle clean build. So it seems like gradle doesn't find sources and gradle also doesn't execute the tests. There is no test report generated and the test result html file doesn't show any executed test.

This is my gradle file:

buildscript {
    repositories {
        maven {
            url "${nexusUrl}/content/groups/public/"
            credentials {
                username "$nexusUsername"
                password "$nexusPassword"
            }
        }
    }

    dependencies {
        classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.6"
    }
}


apply plugin: 'maven'
apply plugin: 'java'
apply plugin: "org.sonarqube"
apply plugin: "jacoco"

jar {
    baseName = 'xxx-trading-lib'
    version = '0.0.1-SNAPSHOT'
}

sourceCompatibility = 11
targetCompatibility = 11

repositories {
    maven {
        url "${nexusUrl}/content/groups/public/"
        credentials {
            username "$nexusUsername"
            password "$nexusPassword"
        }
    }
}


group 'de.xxx.libraries'
version '1.0-SNAPSHOT'

sourceCompatibility = 11
targetCompatibility = 11


dependencies {
    compileOnly 'org.projectlombok:lombok:1.18.8'
    annotationProcessor 'org.projectlombok:lombok:1.18.8'

    compile group: 'com.google.guava', name: 'guava', version: '28.0-jre'
    compile group: 'org.joda', name: 'joda-money', version: '1.0.1'
    compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.9'
    compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
    compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25'

    testCompile group: 'org.assertj', name: 'assertj-core', version: '3.12.2'
    testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.5.0'
    testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.5.0'


}

task sourcesJar(type: Jar, dependsOn:classes) {
    classifier = 'sources'
    from sourceSets.main.allSource
}

artifacts {
    archives sourcesJar
}

uploadArchives {
    repositories {
        mavenDeployer {

            repository(url: "${nexusUrl}/content/repositories/xxx-trading-release") {
                pom.artifactId = 'xxx-trading-release'
                authentication(userName: nexusUsername, password: nexusPassword)

                pom.version='0.0.1-RELEASE'
                pom.artifactId='xxx-trading-release'
                pom.groupId ='de.xxx.components'

            }


            snapshotRepository(url: "${nexusUrl}/content/repositories/xxx-trading-snapshot") {
                pom.artifactId = 'xxx-trading-snapshot'
                authentication(userName: nexusUsername, password: nexusPassword)

                pom.version='0.0.1-SNAPSHOT'
                pom.artifactId='xxx-trading-snapshot'
                pom.groupId ='de.xxx.components'
            }
        }
    }
}

I also deleted the build folder and checked whether the class files will be generated and this works fine. There are new class files afterwards. Has anyone any idea what I'm doing wrong here? I'm using gradle 5.2.1 and java 11.

Edit: It seems like it interupts, because it couldn't find java.lang.object:

23:10:45.359 [DEBUG] [TestEventLogger] Gradle Test Run :test STARTED
23:10:45.370 [DEBUG] [org.gradle.api.internal.tasks.testing.detection.AbstractTestFrameworkDetector] test-class-scan : failed to scan parent class java/lang/Object, could not find the class file
23:10:45.371 [DEBUG] [org.gradle.api.internal.tasks.testing.detection.AbstractTestFrameworkDetector] test-class-scan : failed to scan parent class java/lang/Object, could not find the class file
23:10:45.371 [DEBUG] [TestEventLogger]
23:10:45.371 [DEBUG] [TestEventLogger] Gradle Test Run :test PASSED 
like image 979
n00bst3r Avatar asked Dec 17 '22 16:12

n00bst3r


1 Answers

You have to enable JUnit support in your test configuration. For JUnit 5, add the following to your gradle build file:

test {
    useJUnitPlatform()
}
like image 95
jarnbjo Avatar answered Dec 28 '22 22:12

jarnbjo