Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin Multi-module Project Dependency is Unresolved in test Lifecycle

Project structure: Pure Kotlin as multi module maven application

kotlinspringboot (root-module)

  • api

  • integration-tests

Problem: When I run

$ cd ./kotlingspringboot/integration-tests/
$ mvn test

or

$ cd ./kotlingspringboot/integration-tests/
$ mvn kotlin:test-compile

I get following compilation error regarding unresolved reference for a class from api module :

[ERROR] Failed to execute goal org.jetbrains.kotlin:kotlin-maven-plugin:1.2.21:test-compile (test-compile) on project hello-integration-tests: Compilation failure: Compilation failure:
[ERROR] C:\workspace\kotlinspringboot\integration-tests\src\test\kotlin\org\ildar\hello\integration\HelloEndpointTests.kt:[6,18] Unresolved reference: SpringKotlinHelloWorldApplication

Note: I've ran previously mvn clean install and verified that .m2 cache contains valid api module jar.

api (sub-module) pom.xml

    ....
    <parent>
        <artifactId>kotlin-spring-boot</artifactId>
        <groupId>org.ildar</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>hello-api</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
  ....

integration-tests (sub-module) pom.xml

<parent>
    <artifactId>kotlin-spring-boot</artifactId>
    <groupId>org.ildar</groupId>
    <version>1.0-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<artifactId>hello-integration-tests</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
    <testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
    <plugins>
        <plugin>
            <artifactId>kotlin-maven-plugin</artifactId>
            <groupId>org.jetbrains.kotlin</groupId>
            <version>${kotlin.version}</version>
            <executions>
                <execution>
                    <id>compile</id>
                    <goals> <goal>compile</goal> </goals>
                </execution>

                <execution>
                    <id>test-compile</id>
                    <goals> <goal>test-compile</goal> </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Link to a project on github : https://github.com/IldarGalikov/kotlinspringboot

like image 402
Ildar Galikov Avatar asked Feb 23 '18 15:02

Ildar Galikov


1 Answers

Since Spring removed the "MODULE" Layout in Spring Boot 2.0, maven was complaining about a non existent LayoutType ENUM when trying Christophs answer.

Looking at the Docs though helped me resolve the issue: https://docs.spring.io/spring-boot/docs/current/maven-plugin/examples/repackage-classifier.html

Specifically adding this to the spring-boot-maven-plugin:

<executions>
  <execution>
    <id>repackage</id>
    <configuration>
      <classifier>exec</classifier>
    </configuration>
  </execution>
</executions>
like image 104
Marcel Fraas Avatar answered Sep 23 '22 01:09

Marcel Fraas