迁移到Gradle 4.0后,Scala,Kotlin和Java混合项目在compileScala上失败

时间:2018-08-20 13:34:14

标签: java scala gradle kotlin jvm

我有一个可以在Gradle 3.5上正常运行的项目,但是Zinc编译器通过Java文件时,编译scala失败。我知道在4.0中添加的生成缓存,并且重写该功能以使一个输出目录不变。我附加了gradle文件和来自gradle的堆栈跟踪。任何尝试的建议都将不胜感激,在过去的几天里,我在这个问题上遇到了麻烦。

    group 'com.g'
version '1.0-SNAPSHOT'

buildscript {
    ext.kotlin_version = '1.2.60'
    repositories {
        mavenCentral()
//        maven {
//            url "https://plugins.gradle.org/m2/"
//        }
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath ('org.springframework.boot:spring-boot-gradle-plugin:1.5.15.RELEASE')
//        classpath "com.gradle:build-scan-plugin:1.15.2"
    }
}

//apply plugin: "com.gradle.build-scan"
apply plugin: 'org.springframework.boot'
apply plugin: 'kotlin'
apply plugin: 'java'
apply plugin: 'scala'
apply plugin: 'idea'

sourceCompatibility = 1.8
targetCompatibility = 1.8

//tasks.compileJava.dependsOn compileScala
//tasks.compileScala.dependsOn.remove("compileJava")

sourceSets.main.scala.srcDirs = ['src/main/scala', 'src/main/java']
sourceSets.main.java.srcDirs = []
sourceSets.main.kotlin.srcDirs = ['src/main/kotlin', 'src/main/java']
//sourceSets.main.output.classesDir = new File(buildDir, "classes/main")

repositories {
    jcenter()
    mavenLocal()
    mavenCentral()
    maven {
        url "https://oss.sonatype.org/content/repositories/snapshots"
    }
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"

    compile 'org.slf4j:slf4j-api:1.7.5'

//    zinc 'com.typesafe.zinc:zinc:0.3.9'
//    zinc 'org.scala-lang:scala-library:' + scalaVersion
//    zinc 'org.scala-lang:scala-reflect:' + scalaVersion

//    zinc 'com.typesafe.zinc:zinc:0.3.7'
    // scala
    compile "org.scala-lang:scala-library:" + scalaVersion
    compile "org.scala-lang:scala-reflect:" + scalaVersion
    compile "org.scala-lang:scala-compiler:" + scalaVersion
//    compile group: 'org.scala-lang', name: 'scala-library', version: '2.12.6'
//    compile group: 'org.scala-lang', name: 'scala-reflect', version: '2.12.6'
//    compile group: 'org.scala-lang', name: 'scala-compiler', version: '2.12.6'

    // spark
    compile('org.apache.spark:spark-mllib_2.11:2.3.1')
//    compile 'org.apache.spark:spark-sql_2.11:2.1.0'
//    compile 'org.apache.spark:spark-streaming-flume-assembly_2.11:2.1.0'
//    compile 'org.apache.spark:spark-graphx_2.11:2.1.0'
//    compile 'org.apache.spark:spark-launcher_2.11:2.1.0'
//    compile 'org.apache.spark:spark-catalyst_2.11:2.1.0'
//    compile 'org.apache.spark:spark-streaming_2.11:2.1.0'
    compile 'org.apache.spark:spark-core_2.11:2.3.1'
//     https://mvnrepository.com/artifact/org.codehaus.janino/commons-compiler
    compile group: 'org.codehaus.janino', name: 'commons-compiler', version: '3.0.8'
    compile group: 'org.codehaus.janino', name: 'janino', version: '3.0.8'

    // postgres
    compile group: 'org.postgresql', name: 'postgresql', version: '9.3-1104-jdbc4'

    // hibernate
    compile group: 'org.hibernate', name: 'hibernate-core', version: '5.2.13.Final'
    compile group: 'org.hibernate', name: 'hibernate-ehcache', version: '5.2.13.Final'
    compile group: 'org.hibernate', name: 'hibernate-entitymanager', version: '5.2.13.Final'
    compile group: 'org.hibernate', name: 'hibernate-envers', version: '5.2.13.Final'

    // spring
    compile group: 'org.springframework', name: 'spring-web', version: '5.0.8.RELEASE'
    compile group: 'org.springframework.data', name: 'spring-data-jpa', version: '2.0.9.RELEASE'
    compile('org.springframework.boot:spring-boot-starter:1.5.15.RELEASE') {
        exclude group: 'org.slf4j'
    }

    // open csv
    compile group: 'com.opencsv', name: 'opencsv', version: '4.1'

    // jersey
    compile group: 'com.sun.jersey', name: 'jersey-server', version: '1.19.4'
    compile group: 'com.sun.jersey', name: 'jersey-json', version: '1.19.4'

    // jbcrypt
    compile group: 'org.mindrot', name: 'jbcrypt', version: '0.4'

    // jetty
    compile group: 'org.eclipse.jetty', name: 'jetty-servlet', version: '7.6.0.v20120127'
    compile group: 'org.eclipse.jetty', name: 'jetty-webapp', version: '7.6.0.v20120127'

    //todo delete
    compile group: 'com.wordnik', name: 'swagger-jaxrs_2.10', version: '1.3.0'

    // log4j
    compile group: 'log4j', name: 'log4j', version: '1.2.17'

    compile group: 'commons-io', name: 'commons-io', version: '2.5'
}

task run(type: JavaExec, dependsOn: classes) {
    main = mainClassFile
    classpath sourceSets.main.runtimeClasspath
    classpath configurations.runtime
}

task wrapper(type: Wrapper) {
    gradleVersion = '4.0'
}

以及堆栈跟踪:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':compileScala'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
    at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
    at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:242)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:317)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:309)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:185)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:95)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:235)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:224)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:121)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:77)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:102)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:96)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:612)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:567)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:96)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:46)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: org.gradle.api.internal.tasks.compile.CompilationFailedException: javac returned nonzero exit code
    at org.gradle.api.internal.tasks.scala.ZincScalaCompiler$Compiler.execute(ZincScalaCompiler.java:83)
    at org.gradle.api.internal.tasks.scala.ZincScalaCompiler.execute(ZincScalaCompiler.java:52)
    at org.gradle.api.internal.tasks.scala.ZincScalaCompiler.execute(ZincScalaCompiler.java:38)
    at org.gradle.api.internal.tasks.compile.daemon.AbstractDaemonCompiler$WorkerCompileSpec.compile(AbstractDaemonCompiler.java:74)
    at org.gradle.api.internal.tasks.compile.daemon.AbstractDaemonCompiler$CompilerDaemonServer.execute(AbstractDaemonCompiler.java:82)
    at org.gradle.api.internal.tasks.compile.daemon.AbstractDaemonCompiler$CompilerDaemonServer.execute(AbstractDaemonCompiler.java:78)
    at org.gradle.process.internal.worker.request.WorkerAction.run(WorkerAction.java:91)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:146)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:128)
    at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:404)
    ... 3 more
Caused by: javac returned nonzero exit code
    at sbt.compiler.JavaCompiler$JavaTool0.compile(JavaCompiler.scala:97)
    at sbt.compiler.JavaTool$class.apply(JavaCompiler.scala:54)
    at sbt.compiler.JavaCompiler$JavaTool0.apply(JavaCompiler.scala:84)
    at sbt.compiler.JavaCompiler$class.compile(JavaCompiler.scala:35)
    at sbt.compiler.JavaCompiler$JavaTool0.compile(JavaCompiler.scala:84)
    at sbt.compiler.JavaCompiler$class.compileWithReporter(JavaCompiler.scala:40)
    at sbt.compiler.JavaCompiler$JavaTool0.compileWithReporter(JavaCompiler.scala:84)
    at sbt.compiler.AggressiveCompile$$anonfun$3$$anonfun$compileJava$1$1.apply$mcV$sp(AggressiveCompile.scala:121)
    at sbt.compiler.AggressiveCompile$$anonfun$3$$anonfun$compileJava$1$1.apply(AggressiveCompile.scala:121)
    at sbt.compiler.AggressiveCompile$$anonfun$3$$anonfun$compileJava$1$1.apply(AggressiveCompile.scala:121)
    at sbt.compiler.AggressiveCompile.sbt$compiler$AggressiveCompile$$timed(AggressiveCompile.scala:168)
    at sbt.compiler.AggressiveCompile$$anonfun$3.compileJava$1(AggressiveCompile.scala:120)
    at sbt.compiler.AggressiveCompile$$anonfun$3.apply(AggressiveCompile.scala:142)
    at sbt.compiler.AggressiveCompile$$anonfun$3.apply(AggressiveCompile.scala:84)
    at sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:66)
    at sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:64)
    at sbt.inc.IncrementalCommon.cycle(IncrementalCommon.scala:32)
    at sbt.inc.Incremental$$anonfun$1.apply(Incremental.scala:72)
    at sbt.inc.Incremental$$anonfun$1.apply(Incremental.scala:71)
    at sbt.inc.Incremental$.manageClassfiles(Incremental.scala:99)
    at sbt.inc.Incremental$.compile(Incremental.scala:71)
    at sbt.inc.IncrementalCompile$.apply(Compile.scala:54)
    at sbt.compiler.AggressiveCompile.compile2(AggressiveCompile.scala:159)
    at sbt.compiler.AggressiveCompile.compile1(AggressiveCompile.scala:68)
    at com.typesafe.zinc.Compiler.compile(Compiler.scala:201)
    at com.typesafe.zinc.Compiler.compile(Compiler.scala:183)
    at com.typesafe.zinc.Compiler.compile(Compiler.scala:174)
    at com.typesafe.zinc.Compiler.compile(Compiler.scala:165)
    at org.gradle.api.internal.tasks.scala.ZincScalaCompiler$Compiler.execute(ZincScalaCompiler.java:81)
    ... 14 more

0 个答案:

没有答案