Referencia no resuelta de Kotlin: println de gradle en la CLI

Poner una instrucción println antes de una function kotlin devuelve lockings. 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 comstacktion FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':compileKotlin'. > Comstacktion 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: Comstacktion 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$ 

Sacando la línea ofensiva, una salida exitosa:

 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 comstacktion > 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(); } } 

kotlin:

 package demo; class Foo val PI = 3.14 var x = 0 fun bar() { x += 1 } fun doubleUp(value: Int): Int { return value * 2 } 

file de compilation:

 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 { } 

ambiente:

 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$ 

proyecto:

 . ├── 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 

Es lo más simple posible, Java invoca a Kotlin. No estoy seguro de qué otra manera puedo simplificarlo. Este es un problema de versión ?

Mientras estoy usando netbeans gradle solo se ejecuta desde la CLI. Incluso puedo eliminar los files NB si eso resulta útil.

Probablemente no estoy imprimiendo correctamente en la console.

doh. kotlin requerido .

 thufir@dur:~/NetBeansProjects/kotlin$ thufir@dur:~/NetBeansProjects/kotlin$ gradle clean shadowJar > Task :compileKotlin Using Kotlin incremental comstacktion > 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" } 

tiene que agregar la dependencia.

  • Kotlin utiliza la interfaz de callback de Java
  • String :: toByteArray () no se comstack en Kotlin
  • Llame al object Kotlin con la delegación de class de Java como método estático
  • Buscador privado y establecedor público para una propiedad de Kotlin
  • Kotlin, estructura del proyecto
  • Arquitectura del propio SDK - API de método asíncrono en Kotlin
  • ¿Es posible build una aplicación web completa de Node.js usando Kotlin?
  • Llamar a kotlin funciones que son palabras key en java de java?
  • Conversión de la implementación Thread / Runnable de Java a Kotlin
  • ¿Por qué algunos methods de configuration de Java se convierten automáticamente en properties de Kotlin pero otros no?
  • Kotlin: No se puede usar GenericTypeIndicator para llamar al getValue de Firebase Database