Can't run Scalatest with Gradle

前端 未结 5 437
醉梦人生
醉梦人生 2021-02-02 09:28
task scalaTest(dependsOn: testClasses) << {
    description = \'Runs Scalatest suite\'
    ant.taskdef(name: \'scalatest\',
            classname: \'org.scalatest.         


        
5条回答
  •  一整个雨季
    2021-02-02 09:44

    As of Gradle 3.2.1, following root build.gradle runs both JUnit and ScalaTest code. This code is for multi-project build, enabled via settings.gradle, that's why subprojects used.
    Plus, it's on purpose uses explicit Gradle API, to minimize Gradle DSL magic.

    description = 'root project'
    
    def enableScalaTest(Project project) {
        Task scalaTest = project.task(
                [
                        'dependsOn': 'testClasses',
                        'description': 'Runs ScalaTest tests in the project'
                ],
                'scalaTest',
                {
                    ext.inputDir = project.tasks.getByName('compileTestScala').destinationDir
                    inputs.dir(ext.inputDir)
                }
        )
    
        scalaTest.doLast({
            ant.taskdef(name: 'scalatest',
                    classname: 'org.scalatest.tools.ScalaTestAntTask',
                    classpath: project.sourceSets.test.runtimeClasspath.asPath)
            ant.scalatest(runpath: ext.inputDir,
                    fork: 'false',
                    haltonfailure: 'true')
                    { reporter(type: 'stdout') }
        })
    
        project.getTasks().getByName('build').dependsOn(scalaTest)
    }
    
    subprojects {
        apply plugin: 'scala'
    
        repositories {
            mavenCentral()
        }
    
        dependencies {
            compile 'org.scala-lang:scala-library:2.12.1'
    
            testCompile 'junit:junit:4.12'
            testCompile 'org.scalatest:scalatest_2.12:3.0.1'
        }
    
        enableScalaTest(delegate)
    }
    

提交回复
热议问题