Using Kotlin classes from jar built with kotlin-ma

2019-07-22 06:54发布

问题:

I've built a Java/Kotlin hybrid lib using kotlin-maven-plugin (v 1.2.21). The lib is actually a Spring Boot app (v 1.5.9)

Now, when I declare it as a dependency in another project I face strange issues : - My IDE (Intellij) is able to find the classes I need : auto-completion proposes me the classes, and I have no error - But when I try to build my application, I get compilation errors, saying the packages (and therefore the class) I am trying to import don't exist.

When I expand the jar in the IDE, I can see that the classes exist in the expected package, under a BOOT-INF/classes directory.

So I am a bit confused... is there a specific config to put in kotlin-maven-plugin , so that the generated jar can be used by others ?

Thanks

回答1:

OK, so actually, it had nothing to do with Kotlin, but everything with Spring Boot...

Because of the change of structure in Spring Boot after 1.4.0 version as explained here, it's now required to add this config if you want to be able to import the jar

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <classifier>exec</classifier>
    </configuration>
</plugin>