Unresolved reference: javaClass


#1

I'm having trouble compiling Kotlin projects with Maven. I followed Kotlin+Build+Tools#KotlinBuildTools-Maven and added org.jetbrains.kotlin:kotlin-stdlib as a dependency. Everything works fine in the IDE but on the command line I get:

Unresolved reference: javaClass

Attached you'll find a minimal project to reproduce the issue. IIRC this used to work with older versions of the plugin. Did I do something wrong or is this a bug in the plugin?



kotlin-maven-bug.tar.gz (10 KB)

#2

You have to add missing references to JetBrains Maven repository in your pom.xml:

  <repositories>   <repository>            <id>jetbrains-all</id>            <url>http://repository.jetbrains.com/all</url&gt;   </repository>   </repositories>

  <pluginRepositories>
  <pluginRepository>
           <id>jetbrains-all</id>
           <url>http://repository.jetbrains.com/all</url&gt;
  </pluginRepository>
  </pluginRepositories>


See Kotlin Build Tools wiki page for extra details on using Kotlin with Maven.

It could have work before because you may have had Kotlin maven plugin in your local Maven repository from some Kotlin samples.   


#3

I have the <repositories> and <pluginRepositories> in the settings.xml as is recommended, adding it to the POM makes no difference.

When I remove them from pom.xml and settings.xml I get the following message:

$mvn clean package [INFO] Scanning for projects... [INFO]                                                                    [INFO] ------------------------------------------------------------------------ [INFO] Building kotlin-maven-bug 1.0.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [WARNING] The POM for org.jetbrains.kotlin:kotlin-maven-plugin:jar:0.4.297 is missing, no dependency information available [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.276s [INFO] Finished at: Mon Feb 04 18:57:46 CET 2013 [INFO] Final Memory: 4M/119M [INFO] ------------------------------------------------------------------------ [ERROR] Plugin org.jetbrains.kotlin:kotlin-maven-plugin:0.4.297 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.jetbrains.kotlin:kotlin-maven-plugin:jar:0.4.297: Failure to find org.jetbrains.kotlin:kotlin-maven-plugin:pom:0.4.297 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException

as you can see this is a different error and points to the issue that the plugin that can't be resolved.

However the error I’m getting is:


$mvn clean package
[INFO] Scanning for projects…
[INFO]                                                                   
[INFO] ------------------------------------------------------------------------
[INFO] Building kotlin-maven-bug 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] — maven-clean-plugin:2.4.1:clean (default-clean) @ kotlin-maven-bug —
[INFO] Deleting /home/user/git/kotlin-maven-bug/target
[INFO]
[INFO] — maven-resources-plugin:2.5:resources (default-resources) @ kotlin-maven-bug —
[debug] execute contextualize
[INFO] Using ‘utf-8’ encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/user/git/kotlin-maven-bug/src/main/resources
[INFO]
[INFO] — maven-compiler-plugin:2.3.2:compile (default-compile) @ kotlin-maven-bug —
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] — kotlin-maven-plugin:0.4.297:compile (compile) @ kotlin-maven-bug —
[INFO] Compiling Kotlin sources from [/home/user/git/kotlin-maven-bug/src/main/kotlin]
[INFO] Classpath: /home/user/git/kotlin-maven-bug/src/main/kotlin:/home/user/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib/0.4.297/kotlin-stdlib-0.4.297.jar:/home/user/.m2/repository/org/jetbrains/kotlin/kotlin-runtime/0.4.297/kotlin-runtime-0.4.297.jar:/home/user/.m2/repository/junit/junit/4.11/junit-4.11.jar:/home/user/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
[INFO] Classes directory is /home/user/git/kotlin-maven-bug/target/classes
[INFO] Using kotlin annotations from /tmp/1360000485221-0/kotlin-jdk-annotations.jar
[INFO]
[INFO] — maven-resources-plugin:2.5:testResources (default-testResources) @ kotlin-maven-bug —
[debug] execute contextualize
[INFO] Using ‘utf-8’ encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/user/git/kotlin-maven-bug/src/test/resources
[INFO]
[INFO] — maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ kotlin-maven-bug —
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] — kotlin-maven-plugin:0.4.297:test-compile (test-compile) @ kotlin-maven-bug —
[INFO] Compiling Kotlin sources from [/home/user/git/kotlin-maven-bug/src/test/kotlin]
[INFO] Classpath: /home/user/git/kotlin-maven-bug/src/test/kotlin:/home/user/git/kotlin-maven-bug/target/classes:/home/user/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib/0.4.297/kotlin-stdlib-0.4.297.jar:/home/user/.m2/repository/org/jetbrains/kotlin/kotlin-runtime/0.4.297/kotlin-runtime-0.4.297.jar:/home/user/.m2/repository/junit/junit/4.11/junit-4.11.jar:/home/user/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
[INFO] Classes directory is /home/user/git/kotlin-maven-bug/target/test-classes
[INFO] Using kotlin annotations from /tmp/1360000488945-0/kotlin-jdk-annotations.jar
ERROR: /home/user/git/kotlin-maven-bug/src/test/kotlin/AdderTest.kt: (9, 9) Unresolved reference: javaClass
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.308s
[INFO] Finished at: Mon Feb 04 18:54:50 CET 2013
[INFO] Final Memory: 37M/229M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.jetbrains.kotlin:kotlin-maven-plugin:0.4.297:test-compile (test-compile) on project kotlin-maven-bug: Compilation error. See log for more details -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

As you can see this is a different error, all the plugins and dependencies could be resolved and are in the local repository.

Does the project build on your machine with the repositories in settings.xml or pom.xml?


#4

M5 fixes it


#5

M5? How did you fix this problem?


#6

This thread is 4 years old. If you have a problem, please create a new forum topic or a YouTrack issue.


#7

Now I use the Kotlin-android-extensions for android ,
and i have the same error for build the project


#8

What error exactly? javaClass existed only in pre-1.0 versions of Kotlin; use ::class.java in current versions.


#9

Kotlin’s plugin still uses “javaClass” when generating “equals” implementations:

if (this === other) return true
if (other?.javaClass != javaClass) return false


#10

This is a different javaClass. Previously, a top-level function javaClass<Foo> existed.