Failed to create kotlin javascript maven project

Hello.

I’m trying to setup a maven project to compile some kotlin code to javascript.

I’m using kotlin 0.8.11 (the latest IDEA plugin version available, the latest kotlin version is 0.8.679, but it’s incopatible with the plugin).

kotlin-maven-plugin with ‘js’ goal works well until I’m not trying to use some native code from kotlin-js-library. I’ve added kotlin-js-library as compile dependency but I’m still can’t import something like js.dom.html.window.
IDEA suggests me to import folders from the library but not actual packages declared there (see screenshot below)

The kotlin-maven-plugin also fails to compile from cmd.
A little project to reproduce:

/pom.xml
<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>apomelov.samplewebapp</groupId>
  <artifactId>client</artifactId>
  <version>1.0-SNAPSHOT</version>
  <properties><kotlin.version>0.8.11</kotlin.version></properties>
  <dependencies>
  <dependency>
           <groupId>org.jetbrains.kotlin</groupId>
           <artifactId>kotlin-stdlib</artifactId>
           <version>${kotlin.version}</version>
  </dependency>
  <dependency>
           <groupId>org.jetbrains.kotlin</groupId>
           <artifactId>kotlin-js-library</artifactId>
           <version>${kotlin.version}</version>
  </dependency>
  </dependencies>
  <build>
  <sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
  <plugins>
           <plugin>
           <artifactId>kotlin-maven-plugin</artifactId>
           <groupId>org.jetbrains.kotlin</groupId>
           <version>${kotlin.version}</version>
           <executions>
                   <execution>
                   <id>compile</id>
                   <phase>compile</phase>
                   <goals><goal>js</goal></goals>
                   </execution>
           </executions>
           </plugin>
  </plugins>
  </build>
</project>


/src/main/kotlin/Main.kt
import js.dom.html.window



fun main(args: Array<String>) {
  window.location.replace(“http://google.com”)
}

When I’m not using maven, but create a kotlin-javascript-project from IDEA’s wizard, everything works well. Code completion suggests me all packages and members.

What am I doing wrong? Why does kotlin-js-library.jar contain source code but not compiled bytecode?

Thanks, Alexey

Hi, Alexey

Sorry for delay.
I’m not master of maven, but maybe it should looks like:

<project>   <modelVersion>4.0.0</modelVersion>   <groupId>apomelov.samplewebapp</groupId>   <artifactId>client</artifactId>   <version>1.0-SNAPSHOT</version>   <properties><kotlin.version>0.8.11</kotlin.version></properties>   <build>   <sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>   <plugins>            <plugin>            <artifactId>kotlin-maven-plugin</artifactId>            <groupId>org.jetbrains.kotlin</groupId>            <version>${kotlin.version}</version>            <dependencies>                    <dependency>                    <groupId>org.jetbrains.kotlin</groupId>                    <artifactId>kotlin-js-library</artifactId>                    <version>${kotlin.version}</version>                    </dependency>            </dependencies>            <executions>                    <execution>                    <id>compile</id>                    <phase>compile</phase>                    <goals><goal>js</goal></goals>                    </execution>            </executions>            </plugin>   </plugins>   </build> </project>

I had a very similar problem with the Java version. Downgrading the version in the Maven POM to 0.8.11 fixed it. Looks like the IDEA plugin got some version skew in it.

Hello, Bashor.

Sorry for my delay. I’ve tried you version of pom. Now the project can be built with maven utility, but the Idea still can’t resolve imports from the standard js library.
How to point it for Idea?

Regards, Alexey

Hi, Alexey

I created issue about that – KT-5723. Feel free to vote or star it for getting notifications about updates.

As workaround You can add  “Kotlin JS” framework in to your IDEA project(Project Settings/Structure -> Modules).