Compiling with module dependency not working


#1

Hi everyone!

I’m having a Kotlin Javascript project where I’ve devided the my kotlin code into two modules. I’m building my project with maven and I’ve created a depency from the one module the other, however it’s not compiling.
Is this supported?

I’ve created an example project where it’s occuring:
https://github.com/jvskriubakken/kotlin-js

Maven build log:

[INFO] Scanning for projects…
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] kotlin-javascript
[INFO] kotlin-js-common
[INFO] kotlin-js-example
[INFO] kotlin-webapp
[INFO]                                                                   
[INFO] ------------------------------------------------------------------------
[INFO] Building kotlin-javascript 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] — maven-install-plugin:2.3.1:install (default-install) @ kotlin-javascript —
[INFO] Installing /Users/joerunds/Code/kotlin-js/pom.xml to /Users/joerunds/.m2/repository/no/logiq/kotlin/javascript/kotlin-javascript/1.0-SNAPSHOT/kotlin-javascript-1.0-SNAPSHOT.pom
[INFO]                                                                   
[INFO] ------------------------------------------------------------------------
[INFO] Building kotlin-js-common 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] — maven-antrun-plugin:1.3:run (ensure-target-classes-dir-before-kotlin-compile) @ kotlin-js-common —
[INFO] Executing tasks
[INFO] Executed tasks
[INFO]
[INFO] — maven-resources-plugin:2.5:resources (default-resources) @ kotlin-js-common —
[debug] execute contextualize
[INFO] Using ‘UTF-8’ encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/joerunds/Code/kotlin-js/kotlin-js-common/src/main/resources
[INFO]
[INFO] — maven-compiler-plugin:2.3.2:compile (default-compile) @ kotlin-js-common —
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] — kotlin-maven-plugin:0.12.200:js (compile) @ kotlin-js-common —
[info] Kotlin Compiler version 0.12.200
[info] Compiling Kotlin sources from [/Users/joerunds/Code/kotlin-js/kotlin-js-common/src/main/kotlin]
[debug] libraryFiles: [/Users/joerunds/.m2/repository/org/jetbrains/kotlin/kotlin-js-library/0.12.200/kotlin-js-library-0.12.200.jar]
[debug] Output:
/Users/joerunds/Code/kotlin-js/kotlin-js-common/target/classes/…/…/js/kotlin-js-common.js
Sources:
/Users/joerunds/Code/kotlin-js/kotlin-js-common/src/main/kotlin/no/logiq/common/Common.kt
[debug] Output:
/Users/joerunds/Code/kotlin-js/kotlin-js-common/target/classes/…/…/js/kotlin-js-common.meta.js
Sources:
/Users/joerunds/Code/kotlin-js/kotlin-js-common/src/main/kotlin/no/logiq/common/Common.kt
[INFO]
[INFO] — maven-dependency-plugin:2.1:unpack (unpack) @ kotlin-js-common —
[INFO] Configured Artifact: org.jetbrains.kotlin:kotlin-js-library:0.12.200:jar
[INFO] kotlin-js-library-0.12.200.jar already unpacked.
[INFO]
[INFO] — maven-resources-plugin:2.5:testResources (default-testResources) @ kotlin-js-common —
[debug] execute contextualize
[INFO] Using ‘UTF-8’ encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/joerunds/Code/kotlin-js/kotlin-js-common/src/test/resources
[INFO]
[INFO] — maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ kotlin-js-common —
[INFO] No sources to compile
[INFO]
[INFO] — maven-surefire-plugin:2.10:test (default-test) @ kotlin-js-common —
[INFO] No tests to run.
[INFO] Surefire report directory: /Users/joerunds/Code/kotlin-js/kotlin-js-common/target/surefire-reports


T E S T S

Results :

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

[INFO]
[INFO] — maven-jar-plugin:2.3.2:jar (default-jar) @ kotlin-js-common —
[INFO]
[INFO] — maven-install-plugin:2.3.1:install (default-install) @ kotlin-js-common —
[INFO] Installing /Users/joerunds/Code/kotlin-js/kotlin-js-common/target/kotlin-js-common-1.0-SNAPSHOT.jar to /Users/joerunds/.m2/repository/no/logiq/kotlin/javascript/kotlin-js-common/1.0-SNAPSHOT/kotlin-js-common-1.0-SNAPSHOT.jar
[INFO] Installing /Users/joerunds/Code/kotlin-js/kotlin-js-common/pom.xml to /Users/joerunds/.m2/repository/no/logiq/kotlin/javascript/kotlin-js-common/1.0-SNAPSHOT/kotlin-js-common-1.0-SNAPSHOT.pom
[INFO]                                                                   
[INFO] ------------------------------------------------------------------------
[INFO] Building kotlin-js-example 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] — maven-antrun-plugin:1.3:run (ensure-target-classes-dir-before-kotlin-compile) @ kotlin-js-example —
[INFO] Executing tasks
[INFO] Executed tasks
[INFO]
[INFO] — maven-resources-plugin:2.5:resources (default-resources) @ kotlin-js-example —
[debug] execute contextualize
[INFO] Using ‘UTF-8’ encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/joerunds/Code/kotlin-js/kotlin-js-example/src/main/resources
[INFO]
[INFO] — maven-compiler-plugin:2.3.2:compile (default-compile) @ kotlin-js-example —
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] — kotlin-maven-plugin:0.12.200:js (compile) @ kotlin-js-example —
[info] Kotlin Compiler version 0.12.200
[info] Compiling Kotlin sources from [/Users/joerunds/Code/kotlin-js/kotlin-js-example/src/main/kotlin]
[warn] artifact no.logiq.kotlin.javascript:kotlin-js-common:jar:1.0-SNAPSHOT:compile is not a Kotlin Javascript Library
[debug] libraryFiles: [/Users/joerunds/.m2/repository/org/jetbrains/kotlin/kotlin-js-library/0.12.200/kotlin-js-library-0.12.200.jar]
[error] /Users/joerunds/Code/kotlin-js/kotlin-js-example/src/main/kotlin/no/logiq/kotlin/Task.kt: (3, 17) Unresolved reference: common
[error] /Users/joerunds/Code/kotlin-js/kotlin-js-example/src/main/kotlin/no/logiq/kotlin/Task.kt: (5, 39) Unresolved reference: Common

Anyone knows what I could be doing wrong?

PS: My project compiled before introducing the common module and the depenency on it.


#2

It seems the problem is in kotlin-js-common/pom.xml --- it produced an archive without JS files in it, so kotlin js compiler doesn't recognize it as a valid Kotlin JavaScript library.

[INFO] Building kotlin-js-example 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ ............................................................... [info] Kotlin Compiler version 0.12.200 [info] Compiling Kotlin sources from [/home/michaeln/mygithub/kotlin-js/kotlin-js-example/src/main/kotlin] [warn] artifact no.logiq.kotlin.javascript:kotlin-js-common:jar:1.0-SNAPSHOT:compile is not a Kotlin Javascript Library

pom.xml contains lines

                   <phase>compile</phase>                    <goals>                            <goal>js</goal>                    </goals>                    <configuration>                            <outputFile>${project.build.outputDirectory}/../../js/${project.artifactId}.js</outputFile>                            <metaFile>${project.build.outputDirectory}/${project.artifactId}.meta.js</metaFile>                    </configuration>

but now meta file should also be created in the same directory which contains translated JS file. Option <metaFile> now is boolean and is true by default.

#3

Hi Michael and thanks your answer!

I’ve now changed metaFile = path to be metaInfo = true
See:
https://github.com/jvskriubakken/kotlin-js/commit/1e4e9bc8a5764f008ded4436e36c31af2d9849fe

But I still have problems compiling

[INFO] Scanning for projects…
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] kotlin-javascript
[INFO] kotlin-js-common
[INFO] kotlin-js-example
[INFO] kotlin-webapp
[INFO]                                                                   
[INFO] ------------------------------------------------------------------------
[INFO] Building kotlin-javascript 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] — maven-install-plugin:2.3.1:install (default-install) @ kotlin-javascript —
[INFO] Installing /Users/joerunds/Code/kotlin-js/pom.xml to /Users/joerunds/.m2/repository/no/logiq/kotlin/javascript/kotlin-javascript/1.0-SNAPSHOT/kotlin-javascript-1.0-SNAPSHOT.pom
[INFO]                                                                   
[INFO] ------------------------------------------------------------------------
[INFO] Building kotlin-js-common 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] — maven-antrun-plugin:1.3:run (ensure-target-classes-dir-before-kotlin-compile) @ kotlin-js-common —
[INFO] Executing tasks
  [mkdir] Created dir: /Users/joerunds/Code/kotlin-js/kotlin-js-common/target/classes
[INFO] Executed tasks
[INFO]
[INFO] — maven-resources-plugin:2.5:resources (default-resources) @ kotlin-js-common —
[debug] execute contextualize
[INFO] Using ‘UTF-8’ encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/joerunds/Code/kotlin-js/kotlin-js-common/src/main/resources
[INFO]
[INFO] — maven-compiler-plugin:2.3.2:compile (default-compile) @ kotlin-js-common —
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] — kotlin-maven-plugin:0.12.200:js (compile) @ kotlin-js-common —
[info] Kotlin Compiler version 0.12.200
[info] Compiling Kotlin sources from [/Users/joerunds/Code/kotlin-js/kotlin-js-common/src/main/kotlin]
[debug] libraryFiles: [/Users/joerunds/.m2/repository/org/jetbrains/kotlin/kotlin-js-library/0.12.200/kotlin-js-library-0.12.200.jar]
[debug] Output:
/Users/joerunds/Code/kotlin-js/kotlin-js-common/target/classes/…/…/js/kotlin-js-common.js
Sources:
/Users/joerunds/Code/kotlin-js/kotlin-js-common/src/main/kotlin/no/logiq/common/Common.kt
[debug] Output:
/Users/joerunds/Code/kotlin-js/kotlin-js-common/target/classes/…/…/js/kotlin-js-common.meta.js
Sources:
/Users/joerunds/Code/kotlin-js/kotlin-js-common/src/main/kotlin/no/logiq/common/Common.kt
[INFO]
[INFO] — maven-dependency-plugin:2.1:unpack (unpack) @ kotlin-js-common —
[INFO] Configured Artifact: org.jetbrains.kotlin:kotlin-js-library:0.12.200:jar
[INFO] Unpacking /Users/joerunds/.m2/repository/org/jetbrains/kotlin/kotlin-js-library/0.12.200/kotlin-js-library-0.12.200.jar to
  /Users/joerunds/Code/kotlin-js/kotlin-js-common/target/classes/…/…/js
  with includes *.js and excludes:null
[INFO]
[INFO] — maven-resources-plugin:2.5:testResources (default-testResources) @ kotlin-js-common —
[debug] execute contextualize
[INFO] Using ‘UTF-8’ encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/joerunds/Code/kotlin-js/kotlin-js-common/src/test/resources
[INFO]
[INFO] — maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ kotlin-js-common —
[INFO] No sources to compile
[INFO]
[INFO] — maven-surefire-plugin:2.10:test (default-test) @ kotlin-js-common —
[INFO] No tests to run.
[INFO] Surefire report directory: /Users/joerunds/Code/kotlin-js/kotlin-js-common/target/surefire-reports


T E S T S

Results :

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

[INFO]
[INFO] — maven-jar-plugin:2.3.2:jar (default-jar) @ kotlin-js-common —
[INFO] Building jar: /Users/joerunds/Code/kotlin-js/kotlin-js-common/target/kotlin-js-common-1.0-SNAPSHOT.jar
[INFO]
[INFO] — maven-install-plugin:2.3.1:install (default-install) @ kotlin-js-common —
[INFO] Installing /Users/joerunds/Code/kotlin-js/kotlin-js-common/target/kotlin-js-common-1.0-SNAPSHOT.jar to /Users/joerunds/.m2/repository/no/logiq/kotlin/javascript/kotlin-js-common/1.0-SNAPSHOT/kotlin-js-common-1.0-SNAPSHOT.jar
[INFO] Installing /Users/joerunds/Code/kotlin-js/kotlin-js-common/pom.xml to /Users/joerunds/.m2/repository/no/logiq/kotlin/javascript/kotlin-js-common/1.0-SNAPSHOT/kotlin-js-common-1.0-SNAPSHOT.pom
[INFO]                                                                   
[INFO] ------------------------------------------------------------------------
[INFO] Building kotlin-js-example 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] — maven-antrun-plugin:1.3:run (ensure-target-classes-dir-before-kotlin-compile) @ kotlin-js-example —
[INFO] Executing tasks
  [mkdir] Created dir: /Users/joerunds/Code/kotlin-js/kotlin-js-example/target/classes
[INFO] Executed tasks
[INFO]
[INFO] — maven-resources-plugin:2.5:resources (default-resources) @ kotlin-js-example —
[debug] execute contextualize
[INFO] Using ‘UTF-8’ encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/joerunds/Code/kotlin-js/kotlin-js-example/src/main/resources
[INFO]
[INFO] — maven-compiler-plugin:2.3.2:compile (default-compile) @ kotlin-js-example —
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] — kotlin-maven-plugin:0.12.200:js (compile) @ kotlin-js-example —
[info] Kotlin Compiler version 0.12.200
[info] Compiling Kotlin sources from [/Users/joerunds/Code/kotlin-js/kotlin-js-example/src/main/kotlin]
[warn] artifact no.logiq.kotlin.javascript:kotlin-js-common:jar:1.0-SNAPSHOT:compile is not a Kotlin Javascript Library
[debug] libraryFiles: [/Users/joerunds/.m2/repository/org/jetbrains/kotlin/kotlin-js-library/0.12.200/kotlin-js-library-0.12.200.jar]
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] kotlin-javascript … SUCCESS [0.178s]
[INFO] kotlin-js-common … SUCCESS [2.860s]
[INFO] kotlin-js-example … FAILURE [0.244s]
[INFO] kotlin-webapp … SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.395s
[INFO] Finished at: Wed Jun 24 11:41:30 CEST 2015
[error] /Users/joerunds/Code/kotlin-js/kotlin-js-example/src/main/kotlin/no/logiq/kotlin/Task.kt: (3, 17) Unresolved reference: common
[error] /Users/joerunds/Code/kotlin-js/kotlin-js-example/src/main/kotlin/no/logiq/kotlin/Task.kt: (5, 39) Unresolved reference: Common
[INFO] Final Memory: 17M/322M
[INFO] ------------------------------------------------------------------------

Maybe I do not understand what you are saying here: “but now meta file should also be created in the same directory which contains translated JS file”?

Looking forward to if anyone could help with understanding this.

Jørund


#4

Hi Jørund!

Let’s take a look at kotlin-js-common.

pom.xml contains the following lines:

                   <goals>
                           <goal>js</goal>
                   </goals>
                   <configuration>
                           <outputFile>{project.build.outputDirectory}/../../js/{project.artifactId}.js</outputFile>
                           <metaInfo>true</metaInfo>
                   </configuration>

We see that kotlin-js-common.js and kotlin-js-common.meta.js will be placed into kotlin-js-common/js, outside of target directory.
The resulting jar target/kotlin-js-common-1.0-SNAPSHOT.jar doesn’t contain nor kotlin-js-common.js  neither kotlin-js-common.meta.js.

It seems you can use something like the following in order to fix build
https://github.com/MichaelNedzelsky/kotlin-js/commit/533995f6b93f49e013b9b1a60ff203adc1f218a9

Michael Nedzelsky


#5

Thanks a lot Michael for your time!

I pulled your pull request and it looks promising, since it now compiled successfully, but however it failed runtime.
See attached picture.
Would you be able to see what’s wrong?


#6

Hello again!

Sorry, my blind mistake. Did not see that I had to add a reference to the common js file in my index.html.

Thanks a lot for your time. It was really helpful. I would never have guesses this my self.

Jørund