在kotlin函数返回之前放置println
语句会崩溃。StackTrace:
thufir@dur:~/NetBeansProjects/kotlin$
thufir@dur:~/NetBeansProjects/kotlin$ gradle clean build --stacktrace
w: Classpath entry points to a non-existent location:
e: /home/thufir/NetBeansProjects/kotlin/src/main/kotlin/example.kt: (14, 5): Unresolved reference: println
> Task :compileKotlin
Using Kotlin incremental compilation
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileKotlin'.
> Compilation error. See log for more details
* Try:
Run with --info or --debug option to get more log output.
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':compileKotlin'.
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:62)
at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ResolveBuildCacheKeyExecuter.execute(ResolveBuildCacheKeyExecuter.java:61)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:97)
at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:87)
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:248)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:79)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:104)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:98)
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:625)
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:580)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: org.gradle.api.GradleException: Compilation error. See log for more details
at org.jetbrains.kotlin.gradle.tasks.TasksUtilsKt.throwGradleExceptionIfError(tasksUtils.kt:8)
at org.jetbrains.kotlin.gradle.tasks.KotlinCompile.processCompilerExitCode(Tasks.kt:359)
at org.jetbrains.kotlin.gradle.tasks.KotlinCompile.callCompiler$kotlin_gradle_plugin(Tasks.kt:333)
at org.jetbrains.kotlin.gradle.tasks.KotlinCompile.callCompiler$kotlin_gradle_plugin(Tasks.kt:231)
at org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile.execute(Tasks.kt:203)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$IncrementalTaskAction.doExecute(DefaultTaskClassInfoStore.java:179)
at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:135)
at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:122)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:121)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:110)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
... 29 more
* Get more help at https://help.gradle.org
BUILD FAILED in 0s
2 actionable tasks: 2 executed
thufir@dur:~/NetBeansProjects/kotlin$
去掉冒犯行,一个成功的输出:
thufir@dur:~/NetBeansProjects/kotlin$
thufir@dur:~/NetBeansProjects/kotlin$ gradle clean runShadow
w: Classpath entry points to a non-existent location:
> Task :compileKotlin
Using Kotlin incremental compilation
> Task :shadowJar
The SimpleWorkResult type has been deprecated and is scheduled to be removed in Gradle 5.0. Please use WorkResults.didWork() instead.
> Task :runShadow
Nov 04, 2017 8:42:47 PM net.bounceme.dur.kotlin.App run
INFO: running
Nov 04, 2017 8:42:47 PM net.bounceme.dur.kotlin.App run
INFO: integer is 2
Nov 04, 2017 8:42:47 PM net.bounceme.dur.kotlin.App run
INFO: integer is 4
BUILD SUCCESSFUL in 1s
7 actionable tasks: 7 executed
thufir@dur:~/NetBeansProjects/kotlin$
Java:
package net.bounceme.dur.kotlin;
import java.util.logging.Logger;
public class App {
private static final Logger LOG = Logger.getLogger(App.class.getName());
private void run() {
LOG.info("running");
int integer = 2;
LOG.info("integer is\t\t" + integer);
new demo.Foo();
demo.ExampleKt.bar();
integer = demo.ExampleKt.doubleUp(integer);
LOG.info("integer is\t\t" + integer);
}
public static void main(String[] args) {
new App().run();
}
}
package demo;
class Foo
val PI = 3.14
var x = 0
fun bar() {
x += 1
}
fun doubleUp(value: Int): Int {
return value * 2
}
plugins {
id 'com.gradle.build-scan' version '1.8'
// id 'java'
id 'application'
id "org.jetbrains.kotlin.jvm" version "1.1.51"
id 'com.github.johnrengelman.shadow' version '2.0.1'
}
buildScan {
licenseAgreementUrl = 'https://gradle.com/terms-of-service'
licenseAgree = 'yes'
//publishAlways()
}
configurations {
provided
}
shadowJar {
baseName = 'kotlinAdder'
classifier = null
version = null
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
mainClassName = 'net.bounceme.dur.kotlin.App'
repositories {
jcenter()
}
configurations {
provided
}
dependencies {
}
thufir@dur:~/NetBeansProjects/kotlin$
thufir@dur:~/NetBeansProjects/kotlin$ kotlin -version
Kotlin version 1.1.51 (JRE 1.8.0_151-b12)
thufir@dur:~/NetBeansProjects/kotlin$
thufir@dur:~/NetBeansProjects/kotlin$ kotlinc -version
info: kotlinc-jvm 1.1.51 (JRE 1.8.0_151-b12)
thufir@dur:~/NetBeansProjects/kotlin$
thufir@dur:~/NetBeansProjects/kotlin$ java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
thufir@dur:~/NetBeansProjects/kotlin$
thufir@dur:~/NetBeansProjects/kotlin$ javac -version
javac 1.8.0_151
thufir@dur:~/NetBeansProjects/kotlin$
.
├── build.gradle
├── gradle
│ └── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── src
├── main
│ ├── java
│ │ └── net
│ │ └── bounceme
│ │ └── dur
│ │ └── kotlin
│ │ └── App.java
│ └── kotlin
│ └── example.kt
└── test
└── java
12 directories, 8 files
可能我只是没有正确地打印到控制台。
多。科特林要求。
thufir@dur:~/NetBeansProjects/kotlin$
thufir@dur:~/NetBeansProjects/kotlin$ gradle clean shadowJar
> Task :compileKotlin
Using Kotlin incremental compilation
> Task :shadowJar
The SimpleWorkResult type has been deprecated and is
scheduled to be removed in Gradle 5.0. Please use WorkResults.didWork() instead.
BUILD SUCCESSFUL in 1s
4 actionable tasks: 4 executed
thufir@dur:~/NetBeansProjects/kotlin$
thufir@dur:~/NetBeansProjects/kotlin$ gradle runShadow
> Task :runShadow
Nov 04, 2017 10:43:44 PM net.bounceme.dur.kotlin.App run
INFO: running
Nov 04, 2017 10:43:44 PM net.bounceme.dur.kotlin.App run
INFO: integer is 2
hellooo from kotlin
Nov 04, 2017 10:43:44 PM net.bounceme.dur.kotlin.App run
INFO: integer is 4
BUILD SUCCESSFUL in 1s
6 actionable tasks: 3 executed, 3 up-to-date
thufir@dur:~/NetBeansProjects/kotlin$
...
plugins {
id 'com.gradle.build-scan' version '1.8'
// id 'java'
id 'application'
id "org.jetbrains.kotlin.jvm" version "1.1.51"
id 'com.github.johnrengelman.shadow' version '2.0.1'
}
buildScan {
licenseAgreementUrl = 'https://gradle.com/terms-of-service'
licenseAgree = 'yes'
//publishAlways()
}
configurations {
provided
}
shadowJar {
baseName = 'kotlinAdder'
classifier = null
version = null
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
mainClassName = 'net.bounceme.dur.kotlin.App'
repositories {
jcenter()
}
configurations {
provided
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.51"
}
必须添加依赖项。
我将gradle文件从Groovy迁移到kotlin dsl。一切都很好,但是有一个问题是从另一个kotlin文件中修改值。我可以导入变量和自动完成只是工作很好,但当我构建项目时,它给我提供了未解决的引用错误。感谢任何帮助。 Gradle版本:7.1.1
我想把我的项目分成几个子项目。IntelliJ IDE的默认渐变设置为: 这种设置可以编译。但我不想在每个子项目中重复这些代码。所以我改变了结构。格雷德尔。kts至 但我有例外: e:C:[…]\建造。格雷德尔。kts:1:12:未解析引用:jetbrains e:C:[…]\建造。格雷德尔。kts:16:9:未解析引用:实现e:C:[…]\建造。格雷德尔。kts:19:20:未解析引用:Kotl
我正在尝试使用静态编程语言DSL,但我无法让它识别我在BuildSrc中定义的对象。它们由IDE解析,但当我编译代码时,它不起作用。 这是我的项目结构: 依赖关系的内容: 项目build.gradle.kts(第一个失败的): 我还想指出,android{…}块在模块gradle文件中无法识别,但我认为这可能是因为编译失败。
我试图将我的android项目迁移到使用gradle kotlin dsl,将所有的build.gradle文件替换为build.gradle.kts文件,并在那里使用kotlin。以前,我曾经有一个kotlin文件,其中包含具有库和版本常量的对象元素(在buildSrc->src->main->kotlin中),例如:
错误消息: .... 设置: Java版本: Java版本“1.8.0\u 31” Java(TM)SE运行时环境(build 1.8.0\u 31-b13) Java HotSpot(TM)64位服务器虚拟机(build 25.31-b07,混合模式) build.gradle