Getting a dev environment setup for working on kotlin/libraries

James, thanks for the additions to the main README.md file that describe how to get your dev environment setup for working on Kotlin.

I’m still having trouble, however.  

I want to fork the project and work on some library tests.  So I do that on github, then do this from the top level directory:

$ for i in update_dependencies build; do ant -f $i.xml; done; (cd libraries/; mvn clean package)

Toward the end of the build, I see this failure:

``

-------------------------------------------------------
T E S T S

Running org.jetbrains.kotlin.site.GenerateSiteTest
Generating the site to ./src/main/templates/…/…/…/target/site
Processing css/bootstrap-responsive.css
Processing css/bootstrap-responsive.min.css
Processing css/bootstrap.css
Processing css/bootstrap.min.css
Processing developers.md
Processing img/glyphicons-halflings-white.png
Processing img/glyphicons-halflings.png
Processing index.html
Processing js/bootstrap.js
Processing js/bootstrap.min.js
Generating library KDocs to ./src/main/templates/…/…/…/target/site/versions/snapshot/apidocs
Tests run: 2, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.876 sec <<< FAILURE!

Results :

Tests in error:
  testGenerateStdlibKDoc(org.jetbrains.kotlin.site.GenerateSiteTest)

Tests run: 2, Failures: 0, Errors: 1, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] kotlin-project … SUCCESS [0.150s]
[INFO] stdlib … SUCCESS [21.807s]
[INFO] kunit … SUCCESS [2.300s]
[INFO] kdoc … SUCCESS [5.609s]
[INFO] kotlin-jdbc … SUCCESS [2.286s]
[INFO] website … FAILURE [5.098s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 37.895s
[INFO] Finished at: Tue Mar 13 09:03:31 PDT 2012
[INFO] Final Memory: 183M/342M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.5:test (default-test) on project website: There are test failures.
[ERROR]
[ERROR] Please refer to /Users/petrovic/Projects/kotlin/libraries/website/target/surefire-reports for the individual test results.

with this in the junit report file:

``

-------------------------------------------------------------------------------
Test set: org.jetbrains.kotlin.site.GenerateSiteTest

Tests run: 2, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.875 sec <<< FAILURE!
testGenerateStdlibKDoc(org.jetbrains.kotlin.site.GenerateSiteTest)  Time elapsed: 1.277 sec  <<< ERROR!
java.lang.RuntimeException: builtin library initialization failed: java.lang.NoClassDefFoundError: com/google/inject/Module
  at org.jetbrains.jet.lang.types.lang.JetStandardLibrary.initialize(JetStandardLibrary.java:75)
  at org.jetbrains.jet.compiler.JetCoreEnvironment.<init>(JetCoreEnvironment.java:60)
  at org.jetbrains.jet.compiler.CompileEnvironment.<init>(CompileEnvironment.java:77)
  at org.jetbrains.jet.cli.KotlinCompiler.exec(KotlinCompiler.java:85)
  at org.jetbrains.kotlin.site.GenerateSiteTest.testGenerateStdlibKDoc(GenerateSiteTest.kt:35)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  at java.lang.reflect.Method.invoke(Method.java:597)
  at junit.framework.TestCase.runTest(TestCase.java:168)
  at junit.framework.TestCase.runBare(TestCase.java:134)
  at junit.framework.TestResult$1.protect(TestResult.java:110)
  at junit.framework.TestResult.runProtected(TestResult.java:128)
  at junit.framework.TestResult.run(TestResult.java:113)
  at junit.framework.TestCase.run(TestCase.java:124)
  at junit.framework.TestSuite.runTest(TestSuite.java:243)
  at junit.framework.TestSuite.run(TestSuite.java:238)
  at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
  at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:59)
  at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:115)
  at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:102)
  at org.apache.maven.surefire.Surefire.run(Surefire.java:180)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  at java.lang.reflect.Method.invoke(Method.java:597)
  at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:350)
  at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1021)
Caused by: java.lang.NoClassDefFoundError: com/google/inject/Module
  at org.jetbrains.jet.lang.resolve.TopDownAnalysisContext.<init>(TopDownAnalysisContext.java:90)
  at org.jetbrains.jet.lang.resolve.TopDownAnalyzer.processStandardLibraryNamespace(TopDownAnalyzer.java:156)
  at org.jetbrains.jet.lang.types.lang.JetStandardLibrary.<init>(JetStandardLibrary.java:144)
  at org.jetbrains.jet.lang.types.lang.JetStandardLibrary.initialize(JetStandardLibrary.java:72)
  … 27 more

Was my invocation of the build valid?  If yes, how to provide the missing dependency?  If not, can someone please point me in the right direction?

Sorry for the trouble, but if I can be a useful idiot on noob build issues, I’m willing and able :slight_smile:

Sorry you're still having trouble :)

Aha - I think its the recent guice dependency changes are not in the kotlin maven plugin; FWIW I tend to enable the “localKotlin” profile by default - so I build against the current local build of kotlin.

So this will work for you I think…

  cd libraries
  mvn -PlocalKotlin

Hopefully we can cut a new maven plugin for kotlin once the guice-dependency changes are settled down…

They are settled down now. Sorry for the inconvenience

I've just explicitly added some dependencies to the website/pom.xml for now so it should build for you now hopefully if you pull changes from the kotlin repo.

Whether you use the “localKotlin” profile or not. Both are working for me here now. Sorry about that!

It's getting better, but still failing.  Now it lacks some of the ASM bytecode stuff.  

I do

$ for i in update_dependencies build; do ant -f $i.xml; done; (cd libraries/; mvn clean package)

and get...

-------------------------------------------------------
T E S T S

Running org.jetbrains.kotlin.site.GenerateSiteTest
Generating the site to ./src/main/templates/…/…/…/target/site
Processing css/bootstrap-responsive.css
Processing css/bootstrap-responsive.min.css
Processing css/bootstrap.css
Processing css/bootstrap.min.css
Processing developers.md
Processing img/glyphicons-halflings-white.png
Processing img/glyphicons-halflings.png
Processing index.html
Processing js/bootstrap.js
Processing js/bootstrap.min.js
Generating library KDocs to ./src/main/templates/…/…/…/target/site/versions/snapshot/apidocs
java.lang.NoClassDefFoundError: org/objectweb/asm/commons/EmptyVisitor
     at java.lang.ClassLoader.defineClass1(Native Method)
     at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
     at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
     at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
     at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
     at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
     at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
     at java.security.AccessController.doPrivileged(Native Method)
     at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
     at org.apache.maven.surefire.booter.IsolatedClassLoader.loadClass(IsolatedClassLoader.java:103)
     at com.intellij.psi.impl.compiled.StubBuildingVisitor.visitField(StubBuildingVisitor.java:319)
     at org.objectweb.asm.ClassReader.accept(Unknown Source)
     at org.objectweb.asm.ClassReader.accept(Unknown Source)
     at com.intellij.psi.impl.compiled.DefaultClsStubBuilderFactory.buildFileStub(DefaultClsStubBuilderFactory.java:45)
     at com.intellij.psi.impl.compiled.ClassFileStubBuilder.buildStubTree(ClassFileStubBuilder.java:45)
     at com.intellij.psi.stubs.StubTreeBuilder.buildStubTree(StubTreeBuilder.java:52)
     at com.intellij.psi.stubs.CoreStubTreeLoader.readOrBuild(CoreStubTreeLoader.java:46)
     at com.intellij.psi.impl

But this works:

$ for i in update_dependencies build; do ant -f $i.xml; done; (cd libraries/; mvn -PlocalKotlin clean package)

I get the idea of using the local build of the Kotlin runtime (KRT).  But.. how exactly does that artifact play with this invocation of maven?  

You sure you've pulled the latest from the upstream git repo? The website/pom.xml should have asm-common in there... https://github.com/JetBrains/kotlin/blob/master/libraries/website/pom.xml#L35

If you do, maybe you need to do this to force a re-download (you could have garbaged jars)

rm -rf ~/.m2/repository/asm/asm-common

The normal profile downloads the latest kotlin runtime & compiler jars from Artefactory via Ivy (as unfortnately we don't yet have snapshots or releases in a real maven repo).

The localKotlin profile just sets the classpath of the kotlin maven plugin to use the local Kotlin jars when compiling. The latter is very handy if you’re changing the standard library and want to use the local compiler/stdlib build when compiling - rather than the nightly snapshot builds. It saves waiting 24 hours before being able to use a new standard library API :slight_smile:

jstrachan wrote:

You sure you’ve pulled the latest from the upstream git repo? The website/pom.xml should have asm-common in there…
https://github.com/JetBrains/kotlin/blob/master/libraries/website/pom.xml#L35

If you do, maybe you need to do this to force a re-download (you could have garbaged jars)

rm -rf ~/.m2/repository/asm/asm-common

Yeah, you're right.  I was working on my fork of jetbrains/kotlin.

Hmm.  How am I going to keep my fork in sync without getting twisted around my axle now and then?

Here's instructions on how to pull upstream changes & merge them http://help.github.com/fork-a-repo/

Perfect.  I knew about this in the back of my mind, but I'm still glad I asked.

Speaking of maven, I notice with encouragement that the libraries/ directory appears to be fully mavenized, complete with modules and parent-child relationships wired in.

Doesn’t this mean we can find a way to not include in VCS the IDEA project config files, such as this type of stuff in an .idea directory?

``

$ git st

On branch master

Changes not staged for commit:

  (use “git add <file>…” to update what will be committed)

  (use “git checkout – <file>…” to discard changes in working directory)

#     modified:   libraries/.idea/misc.xml
#     modified:   libraries/.idea/runConfigurations/TestAll.xml


I mean, maven means you don’t have to version IDE configs, right, so we can git-ignore these.

I also think the libraries POM should include this property:

  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

Otherwise, maven defaults to MacRoman encoding for my build.

Yeah, I'm not 100% sure if we should be checking in maven-related IDEA project files. I went ahead and commit mine as the top level project has it. Maybe its better not to though?

Done, thanks for the heads up!

I think it's better not to commit IDEA configs into VCS when using Maven.  And I definitely think Maven is the right choice to drive this build.

So, I closed my libraries IDEA project, ran this in libraries/

$ find . -name *.iws -o -name *.ipr -o -name *.iml -o ( -name .idea -a -type d ) | xargs rm -vrf

then went back into IDEA and re-created the project by File -> Open Project -> [double click the libraries/pom.xml file].

From what I can tell, that worked fine.  IDEA recreated this config (and I guess IDEA 11 has gone back to .idea for project overview instead of .ipr files??):

$ find . -name *.iws -o -name *.ipr -o -name *.iml -o ( -name .idea -a -type d ) ./.idea ./kdoc/kdoc.iml ./kotlin-jdbc/kotlin-jdbc.iml ./kotlin-project.iml ./kunit/kunit.iml ./stdlib/stdlib.iml ./website/website.iml

And I opened, e.g., /testlib/test/CollectionTest.kt to make sure I have no red.  No red.

Somebody should try this and sanity check me.

But if we can avoid it, I recommend removing IDEA configs from the VCS.  That should pay off when Eclipse and NetBeans have Kotlin support, as when those users see the POM and no IDEA configs, they’ll just know what to do.

What do you think?

Thanks Mark!

I’ve zapped all the IDEA files from the libraries folder now BTW and they are now ignored by git
https://github.com/JetBrains/kotlin/blob/master/libraries/.gitignore

Cool.

Does double clicking on the libraries/pom.xml file work for you to recreate the IDEA configs?

Yes, worked fine for me

Doing a bit of minor thrashing on this, I found that on starting/stopping IDEA (for whatever that's worth), I had to tell IDEA what the SDK was for the project and I think I had to re-import all Maven projects.  Somehow I got into the situation where, say, the CollectionTest.kt file was showing red.  

I’m not sure where IDEA would even get its notion of which JDK to associate with this project.  Does that come from Maven??  Or some heuristic based on inspection of the code base??  The first sign of trouble was when IDEA did not know what to do with

import java.util.*

in CollectionTest.kt (an arbitrary .kt file for the purposes of this thread).  That’s when I manually configured JDK6 as the SDK for this project.

It’s not red now, but to posterity:  you may have to prod IDEA like this to get rid of red when you bootstrap your IDEA config from the pom.