错误:加载类文件' package.class'时检测到缺失或无效的依赖项

时间:2015-08-17 18:04:29

标签: scala gradle scalatest

我正在尝试使用gradle进行scala测试。         以下是我的build.gradle的样子快照。         我的Scala IntelliJ SDK也指向最新的。我已经在这2天工作但没有成功。我已经尝试更改库或SourceSets但似乎没有任何改变错误消息。     如果我不使用SourceSets,它会抛出所有类文件的错误,无论Java或Scala如何。     以下是我的文件夹结构:

 src
    -main
        -java
        -scala
    -test
       -groovy
       -scala 

    //start of my gradle file.
    apply plugin: 'java'
    apply plugin: 'groovy'
    apply plugin: 'wrapper'
    apply plugin: 'scala'

    sourceCompatibility = 1.8
    version = '1'

    repositories {
        mavenCentral()
        mavenLocal()
        jcenter()
    }

    dependencies {

        //json marshalling
        compile 'org.json4s:json4s-jackson_2.11:3.2.11'

        compile 'com.fasterxml.jackson.core:jackson-databind:2.3.2'
        compile 'com.google.code.gson:gson:2.3.1'
        compile 'com.googlecode.json-simple:json-simple:1.1'

        //scala
        compile "org.scala-lang:scala-library:2.11.7"

        //scala
        testCompile "org.scala-lang:scala-library:2.11.7"
        testCompile(group: 'org.scalatest', name: 'scalatest_2.11', version: '2.2.4')
    }

    sourceSets {
    main {
          scala {
                    srcDirs = ['src/main/scala','src/main/java']
                }
            }
            test {
                scala {
                    srcDirs = ['src/test/scala']
                }
            }
        }

        sourceSets {
            main {
                output.resourcesDir = "build/classes/main"
            }
        }
        //not sure whether an Ant task helps? I grabbed from after a google search.
        test << {
            ant.taskdef(
                    name: 'scalatest',
                    classname: 'org.scalatest.tools.ScalaTestAntTask',
                    classpath: classpath.asPath
            )
            println("test classes dir" + testClassesDir)
            ant.scalatest(
                    runpath: testClassesDir,
                    haltonfailure: 'true',
                    fork: 'false') {
                reporter(type: 'stderr')
                reporter(type: 'junitxml', directory: 'build/reports/junitxml')
            }
        }


    Following is the command I use to run the tests:
    ./gradlew clean test

    and the error log reports:

    :compileTestScala
    error: missing or invalid dependency detected while loading class file 'package.class'.
    Could not access type ScalaObject in package scala,
    because it (or its dependencies) are missing. Check your build definition for
    missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.)
    A full rebuild may help if 'package.class' was compiled against an incompatible version of scala.
    one error found

    Any pointers would be helpful.

0 个答案:

没有答案