Kotlin失败的Gradle构建

时间:2018-08-31 13:46:13

标签: gradle kotlin native

我有一个kotlin软件包,我正在尝试为此编写gradle设置来自动构建。相关的存储库可以在github-> https://github.com/ishankhare07/kotlin-web-server/tree/feature/dynamic-routing

上找到

当前运行gradle buildgradle compileLKotlin失败,并显示以下错误:

e: java.lang.ArrayIndexOutOfBoundsException: 450
    at org.jetbrains.org.objectweb.asm.ClassReader.readUnsignedShort(ClassReader.java:2464)
    at org.jetbrains.org.objectweb.asm.ClassReader.readUTF8(ClassReader.java:2525)
    at org.jetbrains.org.objectweb.asm.ClassReader.readModule(ClassReader.java:761)
    at org.jetbrains.org.objectweb.asm.ClassReader.accept(ClassReader.java:646)
    at org.jetbrains.org.objectweb.asm.ClassReader.accept(ClassReader.java:507)
    at org.jetbrains.kotlin.resolve.jvm.modules.JavaModuleInfo$Companion.read(JavaModuleInfo.kt:67)
    at org.jetbrains.kotlin.cli.jvm.modules.CliJavaModuleFinder.findSystemModule(CliJavaModuleFinder.kt:44)
    at org.jetbrains.kotlin.cli.jvm.modules.CliJavaModuleFinder.access$findSystemModule(CliJavaModuleFinder.kt:25)
    at org.jetbrains.kotlin.cli.jvm.modules.CliJavaModuleFinder$systemModules$1.invoke(CliJavaModuleFinder.kt:37)
    at org.jetbrains.kotlin.cli.jvm.modules.CliJavaModuleFinder$systemModules$1.invoke(CliJavaModuleFinder.kt:25)
    at kotlin.sequences.TransformingSequence$iterator$1.next(Sequences.kt:149)
    at kotlin.sequences.FilteringSequence$iterator$1.calcNext(Sequences.kt:109)
    at kotlin.sequences.FilteringSequence$iterator$1.hasNext(Sequences.kt:133)
    at kotlin.sequences.FlatteningSequence$iterator$1.ensureItemIterator(Sequences.kt:254)
    at kotlin.sequences.FlatteningSequence$iterator$1.hasNext(Sequences.kt:241)
    at kotlin.sequences.SequencesKt___SequencesKt.none(_Sequences.kt:1239)
    at org.jetbrains.kotlin.cli.jvm.compiler.ClasspathRootsResolver.addModularRoots(ClasspathRootsResolver.kt:227)
    at org.jetbrains.kotlin.cli.jvm.compiler.ClasspathRootsResolver.computeRoots(ClasspathRootsResolver.kt:124)
    at org.jetbrains.kotlin.cli.jvm.compiler.ClasspathRootsResolver.convertClasspathRoots(ClasspathRootsResolver.kt:79)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.<init>(KotlinCoreEnvironment.kt:230)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.<init>(KotlinCoreEnvironment.kt:114)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.createForProduction(KotlinCoreEnvironment.kt:409)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.createCoreEnvironment(K2JVMCompiler.kt:286)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.createEnvironmentWithScriptingSupport(K2JVMCompiler.kt:276)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:155)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:63)
    at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:109)
    at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:53)
    at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:92)
    at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:451)
    at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:97)
    at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally(IncrementalCompilerRunner.kt:218)
    at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.access$compileIncrementally(IncrementalCompilerRunner.kt:37)
    at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner$compile$2.invoke(IncrementalCompilerRunner.kt:80)
    at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:92)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.execIncrementalCompiler(CompileServiceImpl.kt:518)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.access$execIncrementalCompiler(CompileServiceImpl.kt:97)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:400)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:97)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:895)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:97)
    at org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:137)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:925)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.doCompile(CompileServiceImpl.kt:894)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:399)
    at jdk.internal.reflect.GeneratedMethodAccessor23.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359)
    at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
    at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:562)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:844)


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileKotlin'.
> Internal compiler error. See log for more details

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s

下面是我的build.gradle文件:

buildscript {
    ext.kotlin_version = '1.2.21'


    dependencies {
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

plugins {
    id "org.jetbrains.kotlin.jvm" version "1.2.21"
    id "com.jfrog.bintray" version "1.7.3"
    id 'maven-publish'
}

repositories {
    jcenter()
    mavenCentral()
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib"
}

jar {
    from {
        configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
    }
}

task sourcesJar(type: Jar, dependsOn: project.classes) {
    from sourceSets.main.allSource
}

publishing {
    publications {
        publishToBintray(MavenPublication) {
            artifact sourcesJar
            groupId 'com.ishankhare.kotlin-server'
        }
    }
}

bintray {
    user = 'ishankhare07'
    key = '9b693a0c46f7021021a2422f3ea837f0ad8e3ea6'
        publications = ['publishToBintray']
    pkg {
        version {
            name = 'v0.0.1'
        }
        repo = 'server'
        name = 'server'
        licenses = ['MIT']
        vcsUrl = 'https://github.com/ishankhare07/kotlin-web-server'
    }

}



sourceSets {
    main.kotlin.srcDirs += "./"
}

使用--info标志运行构建时,我得到以下输出:

Initialized native services in: /Users/ishankhare/.gradle/native
The client will now receive all logging from the daemon (pid: 11054). The daemon log file: /Users/ishankhare/.gradle/daemon/4.10/daemon-11054.out.log
Starting 42nd build in daemon [uptime: 43 mins 31.646 secs, performance: 100%, no major garbage collections]
Using 4 worker leases.
Starting Build
Settings evaluated using settings file '/Users/ishankhare/code/ishan/kotlin-web-server/server/settings.gradle'.
Projects loaded. Root project using build file '/Users/ishankhare/code/ishan/kotlin-web-server/server/build.gradle'.
Included projects: [root project 'server']

> Configure project :
Evaluating root project 'server' using build file '/Users/ishankhare/code/ishan/kotlin-web-server/server/build.gradle'.
All projects evaluated.
Selected primary task 'compileKotlin' from project :
Tasks to be executed: [task ':compileKotlin']
:compileKotlin (Thread[Task worker for ':',5,main]) started.
e: java.lang.ArrayIndexOutOfBoundsException


> Task :compileKotlin FAILED
file or directory '/Users/ishankhare/code/ishan/kotlin-web-server/server/src/main/kotlin', not found
file or directory '/Users/ishankhare/code/ishan/kotlin-web-server/server/src/main/java', not found
Task ':compileKotlin' is not up-to-date because:
  Task has failed previously.
All input files are considered out-of-date for incremental task ':compileKotlin'.
file or directory '/Users/ishankhare/code/ishan/kotlin-web-server/server/src/main/kotlin', not found
file or directory '/Users/ishankhare/code/ishan/kotlin-web-server/server/src/main/java', not found
file or directory '/Users/ishankhare/code/ishan/kotlin-web-server/server/src/main/kotlin', not found
file or directory '/Users/ishankhare/code/ishan/kotlin-web-server/server/src/main/java', not found
Using Kotlin incremental compilation
Options for KOTLIN DAEMON: IncrementalCompilationOptions(super=CompilationOptions(compilerMode=INCREMENTAL_COMPILER, targetPlatform=JVM, reportCategories=[0], reportSeverity=2, requestedCompilationResults=[0]), areFileChangesKnown=false, modifiedFiles=null, deletedFiles=null, workingDir=/Users/ishankhare/code/ishan/kotlin-web-server/server/build/kotlin/compileKotlin, customCacheVersionFileName='gradle-format-version.txt', customCacheVersion=4, resultDifferenceFile=/Users/ishankhare/code/ishan/kotlin-web-server/server/build/kotlin/compileKotlin/build-history.bin, friendDifferenceFile=null, usePreciseJavaTracking=false)
[KOTLIN] deleting /Users/ishankhare/code/ishan/kotlin-web-server/server/build/classes/kotlin/main on error
[KOTLIN] deleting /Users/ishankhare/code/ishan/kotlin-web-server/server/build/classes/kotlin/main on error
:compileKotlin (Thread[Task worker for ':',5,main]) completed. Took 0.087 secs.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileKotlin'.
> Internal compiler error. See log for more details

* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/4.10/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 0s
1 actionable task: 1 executed

1 个答案:

答案 0 :(得分:0)

与arrayindexoutofboundsexception在:基本上看起来像是在寻找东西,没有找到它,因此我的建议失败了,那就是将buildscript ext.kotlin_version ='1.2.21'更新并切换到1.2.61,这很可能解决其寻找和找不到的东西的问题