![](/img/trans.png)
[英]Kotlin compilation error "Unresolved reference" for multi-module project
[英]Creating a multi module project with maven spring and kotlin get unresolved reference
我正在嘗試使用 kotlin 和 spring 構建多模塊 maven 項目。 當 kotlin-maven-plugin 運行編譯階段時出現錯誤。
[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
有趣的是,當我使用“mvn clean”清理我的構建並運行它編譯的項目並運行 spring 應用程序時。
我不知道是什么導致了這個問題。 也許我錯過了一些東西。
這是我的 poms 和我的項目結構。 希望有人可以幫助我。
父 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>
啟動器 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>
網站入口點.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) }
這是我的項目結構。 請注意,當我運行“mvn clean install”命令時,我得到了這個。
當我清理我的項目並運行時,我得到了這個結構。
當我運行 mvn clean install 時,它不會創建目標類,因此我猜它找不到我的 WebsiteEntryPoint。
希望有人可以幫助我。 非常感謝。
我在 intellij 中編譯 kotlin 多模塊項目時遇到了同樣的問題。 命令mvn clean install
產生了與未解決的依賴項相同的錯誤。
正如我所看到的,您的源目錄被命名為 kotlin (就像我之前的項目一樣)。
將我項目中的源目錄重命名為 java 后,問題就解決了...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.