Search code examples
mavenintellij-ideakotlinintellij-14

How do I make IntelliJ respect Maven Kotlin plugin output directory?


I am writing Kotlin and compiling to JavaScript. I also have some HTML/CSS resources. I have a Maven project setup that copies my HTML resources to the build directory and the kotlin-maven-plugin has its outputFile location set to be a subdirectory of the output directory (${project.build.directory}/js/${project.artifactId}.js). When building with maven this behaves exactly as expected and my output directory contains my compiled JavaScript file in the js folder and my HTML/CSS files in the appropriate places.

When I import the project into IntelliJ however, it doesn't respect the outputFile location set in the pom.xml and instead drops my generated JavScript file into target\classes.

I can fix this after import by going into Project Structure > Project Settings > Modules > Paths > Compiler Output > Output Path and changing it to target\js but I would like to be able to setup the pom.xml in such a way that this step is unnecessary.

On a related note, why does setting the output path not result in my HTML/CSS files getting dropped into target\js? It would seem that the output path isn't being respected by the resource copy.

Edit: Here is the pom.xml excert:

<plugin>
    <artifactId>kotlin-maven-plugin</artifactId>
    <groupId>org.jetbrains.kotlin</groupId>
    <version>${kotlin.version}</version>
    <executions>
        <execution>
            <id>js</id>
            <goals>
                <goal>js</goal>
            </goals>
            <configuration>
                <outputFile>${project.build.directory}/js/${project.artifactId}.js</outputFile>
            </configuration>
        </execution>
    </executions>
</plugin>

Solution

  • This looks resolved, or that there is another option. From the issue mentioned in comments to the question (https://youtrack.jetbrains.com/issue/KT-6749):

    When you import maven project in IntelliJ, if "Use Maven output directories" is selected, then the output path will be set to ${project.build.outputDirectory}, which is by default is ${project.build.directory}/classes (see http://maven.apache.org/pom.html for details).

    The following should work:

    <build>
        <outputDirectory>${project.build.directory}/js</outputDirectory>
        ...
    </build>
    

    For now the default value for parameter outputFile (kotlin-maven-plugin, goal:js) is ${project.build.directory}/js/${project.artifactId}.js.

    It seems it should be changed to ${project.build.outputDirectory}/${project.artifactId}.js (commit https://github.com/JetBrains/kotlin/commit/0b35989367291e88568567a293ed7224f809d605)