Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error regarding tools.jar during test run #10

Open
dimsuz opened this issue Mar 2, 2019 · 5 comments
Open

Error regarding tools.jar during test run #10

dimsuz opened this issue Mar 2, 2019 · 5 comments
Labels
question Further information is requested

Comments

@dimsuz
Copy link

dimsuz commented Mar 2, 2019

I have this test

class SampleTest {
  @Test
  fun testTriggersErrorWhenAppliedToClass() {
    kotlinc()
      .withProcessors(ModelGeneratorProcessor())
      .addKotlin("TestModel.kt", """
        fun main() {
        
        }
      """.trimIndent())
      .compile()
      .failed()
      .withErrorContaining("blah")
  }
}

It fails with

org.junit.ComparisonFailure: null 
Expected :blah
Actual   :error: [kapt] 'com.sun.tools.javac.util.Context' class can't be found ('tools.jar' is absent in the plugin classpath). Kapt won't work.

I am using kotlin 1.3.21, The build.gradle contains:

  testImplementation("org.permissionsdispatcher:kompile-testing:0.1.2")
  testImplementation(files(Jvm.current().toolsJar)) // tried to add this, didn't help

Any hints on what do I do wrong?

@dimsuz
Copy link
Author

dimsuz commented Mar 2, 2019

I found this comment about adding -Xplugin tools.jar, not sure if it applies here.

@dimsuz
Copy link
Author

dimsuz commented Mar 2, 2019

For now I managed to solve this by adding

.withClasspath(URLClassLoader.newInstance(arrayOf(File("/usr/lib/jvm/java-8-jdk/lib/tools.jar").toURI().toURL())))

@hotchemi
Copy link
Member

hotchemi commented Mar 3, 2019

👀 Let us check! Thx for your report.

@hotchemi hotchemi added the question Further information is requested label Mar 3, 2019
@dimsuz
Copy link
Author

dimsuz commented Mar 3, 2019

It may have to do with the java I'm using. Host JDK is 1.8 (to be able to run android studio).
But general kapt tasks in all my projects work without problems, so I suspect it has to do with kotlinc command setup used by this library.

I even tried copying your Compiler class into my project and tweaking it by adding full path to my tools.jar in every way I could (using -Xplugin, using kapt3:apoptions, or adding to -classpath) - nothing worked, same damn error every time :)

The workaround in my previous comment somehow works, but turned out that it breaks on first import statement I use, for example for import com.github.dimsuz.stuff it says "unknown reference: github". I'm not sure why this happens on github, because even inserting this import-line in empty .kt file does not produce this error... That's another question though.

@YangShengJia
Copy link

Did you check your jdk path which folder name contain special symbol like '+', I change to '_'. error be fix.
example: folder name is 1.8.0+282 -> 1.8.0_282.
Good luck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants