简体   繁体   中英

Creating a multi module project with maven spring and kotlin get unresolved reference

I am trying to build a multi module maven project with kotlin and spring. I get an error when the kotlin-maven-plugin runs the compile phase.

 [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ starter --- [INFO] Deleting /Users/pnts/IdeaProjects/getyour/base/starter/target [INFO] [INFO] --- git-commit-id-plugin:2.2.6:revision (default) @ starter --- [INFO] [INFO] --- git-commit-id-plugin:2.2.6:revision (get-the-git-infos) @ starter --- [INFO] [INFO] --- kotlin-maven-plugin:1.3.41:compile (compile) @ starter --- [INFO] Applied plugin: 'spring' [ERROR] /Users/pnts/IdeaProjects/getyour/base/starter/src/main/kotlin/org/getyour/webdesign/PlainStarter.kt: (6, 9) Unresolved reference: WebsiteEntryPoint [INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary for parent 0.0.1-SNAPSHOT: [INFO] [INFO] parent............................................. SUCCESS [ 1.178 s] [INFO] common............................................. SUCCESS [ 0.021 s] [INFO] platform-api....................................... SUCCESS [ 4.238 s] [INFO] platform-core...................................... SUCCESS [ 0.215 s] [INFO] platform-bom....................................... SUCCESS [ 0.012 s] [INFO] platform-parent.................................... SUCCESS [ 0.061 s] [INFO] starter............................................ FAILURE [ 0.343 s] [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 6.399 s [INFO] Finished at: 2019-09-27T08:57:04+02:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.jetbrains.kotlin:kotlin-maven-plugin:1.3.41:compile (compile) on project starter: Compilation failure [ERROR] /Users/pnts/IdeaProjects/getyour/base/starter/src/main/kotlin/org/getyour/webdesign/PlainStarter.kt:[6,9] Unresolved reference: WebsiteEntryPoint [ERROR] [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException [ERROR] [ERROR] After correcting the problems, you can resume the build with the command [ERROR] mvn <goals> -rf:starter

The funny thing is when I clean my build with "mvn clean" and run the project it compiles and run the spring application.

Spring starts normal

I dont know what causes this issue. Maybe I am missing something.

Here are my poms and my project structure. Hope somebody can help me with this.

parent pom.xml

 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.8.RELEASE</version> <relativePath/> </parent> <version>0.0.1-SNAPSHOT</version> <artifactId>parent</artifactId> <groupId>org.getyour.webdesign</groupId> <packaging>pom</packaging> <modules> <module>common</module> <module>starter</module> </modules> <.-- properties --> <properties> <kotlin.version>1.3.41</kotlin.version> <spring.boot.version>2.1.8.RELEASE</spring.boot.version> <java.version>1.8</java.version> <main.class>org.getyour.webdesign.WebsiteEntryPoint</main:class> </properties> <.-- repositories --> <repositories> <repository> <id>maven-central</id> <url>http.//central.maven.org/maven2/</url> </repository> </repositories> <build> <sourceDirectory>src/main/kotlin</sourceDirectory> <testSourceDirectory>src/test/kotlin</testSourceDirectory> <pluginManagement> <plugins> <plugin> <.-- Import dependency management from Spring Boot --> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>${spring.boot.version}</version> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>${spring.boot.version}</version> </plugin> <plugin> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-maven-plugin</artifactId> <version>${kotlin.version}</version> </plugin> </plugins> </pluginManagement> <plugins> <.-- kotlin spring compiler plugin --> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>${spring.boot.version}</version> <configuration> <mainClass>${main.class}</mainClass> </configuration> </plugin> <plugin> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-maven-plugin</artifactId> <version>${kotlin.version}</version> <executions> <execution> <id>compile</id> <goals><goal>compile</goal></goals> <phase>process-sources</phase> </execution> <execution> <id>test-compile</id> <goals><goal>test-compile</goal></goals> <phase>process-test-sources</phase> </execution> </executions> <configuration> <args> <arg>-Xjsr305=strict</arg> </args> <compilerPlugins> <plugin>spring</plugin> </compilerPlugins> </configuration> <dependencies> <dependency> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-maven-allopen</artifactId> <version>${kotlin.version}</version> </dependency> <dependency> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-stdlib-jdk8</artifactId> <version>${kotlin.version}</version> </dependency> </dependencies> </plugin> <plugin> <groupId>pl.project13.maven</groupId> <artifactId>git-commit-id-plugin</artifactId> <version>2.2.6</version> <executions> <execution> <id>get-the-git-infos</id> <goals> <goal>revision</goal> </goals> </execution> </executions> <configuration> <dotGitDirectory>${project.basedir}/.git</dotGitDirectory> <prefix /> <verbose>false</verbose> <generateGitPropertiesFile>true</generateGitPropertiesFile> <generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties </generateGitPropertiesFilename> <format>properties</format> <gitDescribe> <skip>false</skip> <always>false</always> <dirty>-dirty</dirty> </gitDescribe> </configuration> </plugin> </plugins> </build> </project>

starter pom.xml

 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <artifactId>parent</artifactId> <groupId>org.getyour.webdesign</groupId> <version>0.0.1-SNAPSHOT</version> </parent> <version>0.0.1-SNAPSHOT</version> <artifactId>starter</artifactId> <packaging>jar</packaging> <dependencyManagement> <dependencies> <dependency> <groupId>org.getyour.webdesign</groupId> <artifactId>platform-bom</artifactId> <version>0.0.1-SNAPSHOT</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>org.getyour.webdesign</groupId> <artifactId>platform-core</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-reflect</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-stdlib-jdk8</artifactId> </dependency> </dependencies> </project>

WebsiteEntryPoint.kt

 package org.getyour.webdesign import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.runApplication /** * Start class of the application * * @author p.tsivelekidis * Created by p.tsivelekidis on 2019-09-20 */ @SpringBootApplication class WebsiteEntryPoint { companion object { fun main(args: Array<String>) { runApplication<WebsiteEntryPoint>(*args) println("Hello!") } } }

PlainStarter.kt

 package org.getyour.webdesign class PlainStarter fun main(args: Array<String>) { WebsiteEntryPoint.main(args) }

Here is my project structure. Notice that when I run the "mvn clean install" command I get this.

project structure after mvn clean install

When I clean my project and just run I get this structure.

project structure after clean and just run project

When I run the mvn clean install it does not create the target classes and I guess for that reason it cant find my WebsiteEntryPoint.

Hope somebody can help me with that. Thanks a lot.

i had the same issue with compiling a kotlin multi module project in intellij. Command mvn clean install produced the same error with the unresolved dependencies.

As i can see your source directories are named kotlin (as in my project before).

After renaming the source directories in my project to java the problem was solved...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM