java kotlin混合变成java编译提示找不到符号

有一个项目,kotlin写了一些逻辑代码,我想加一个controller,新增了一个kotlin方法复用了之前的逻辑,写好之后没有重新编译,直接启动进行测试,整体完全正常没有报错,但是在mvn clean,然后再mvn compile的时候发生了报错,报的是找不到符号,有两个地方,一个是import语句中的kotlin类名,一个是@Resource注入(kotlin类加了@Component注解,交给spring管理了)时候的类名找不到符号。但是IDEA没有标红,点击也可以正常跳转到KOTLIN类文件内,就很奇怪,网上找了不少方法,说是需要先编译kotlin再编译java就能解决,于是修改了pom文件,改成如下顺序,并且需要加上才可以

java 复制代码
<build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <plugin>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-maven-plugin</artifactId>
                <version>1.9.22</version>
                <configuration>
                    <jvmTarget>1.8</jvmTarget>
                    <compilerPlugins>
                        <plugin>lombok</plugin>
                    </compilerPlugins>
                    <pluginOptions>
                        <option>lombok:config=${project.basedir}/lombok.config</option>
                    </pluginOptions>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.jetbrains.kotlin</groupId>
                        <artifactId>kotlin-maven-lombok</artifactId>
                        <version>1.9.22</version>
                    </dependency>
                    <dependency>
                        <groupId>org.projectlombok</groupId>
                        <artifactId>lombok</artifactId>
                        <version>1.18.22</version>
                        <scope>compile</scope>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <id>compile</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>test-compile</id>
                        <phase>test-compile</phase>
                        <goals>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>

        </plugins>
    </build>

但是编译后看控制台输出:

java 复制代码
[INFO] 
[INFO] --- maven-enforcer-plugin:1.4.1:enforce (default-cli) @ ---
[INFO] 
[INFO] --- maven-enforcer-plugin:1.4.1:enforce (banDuplicateClasses-Check) @  ---
[INFO] 
[INFO] --- maven-enforcer-plugin:1.4.1:enforce (check-commons-db-upgrade) @  ---
[INFO] 
[INFO] --- jacoco-maven-plugin:0.7.1.201405082137:prepare-agent (pre-unit-test) @  ---
[INFO] argLine set to -javaagent:/***/org.jacoco.agent-0.7.1.201405082137-runtime.jar=destfile=/***/target/jacoco.exec,excludes=org/sqlite/SQLite
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @  ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 6 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @  ---

仍旧是先编译的java,再次查询资料,修改pom文件如下:

java 复制代码
<build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <plugin>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-maven-plugin</artifactId>
                <version>1.9.22</version>
                <configuration>
                    <jvmTarget>1.8</jvmTarget>
                    <compilerPlugins>
                        <plugin>lombok</plugin>
                    </compilerPlugins>
                    <pluginOptions>
                        <option>lombok:config=${project.basedir}/lombok.config</option>
                    </pluginOptions>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.jetbrains.kotlin</groupId>
                        <artifactId>kotlin-maven-lombok</artifactId>
                        <version>1.9.22</version>
                    </dependency>
                    <dependency>
                        <groupId>org.projectlombok</groupId>
                        <artifactId>lombok</artifactId>
                        <version>1.18.22</version>
                        <scope>compile</scope>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <id>compile</id>
                        <phase>process-sources</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>test-compile</id>
                        <phase>process-test-sources</phase>
                        <goals>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>

        </plugins>
    </build>

注意看这两处区别:

java 复制代码
<phase>process-sources</phase>
<phase>process-test-sources</phase>

修改后编译就发现kotlin在前边先编译,没有报错了,解决问题!

相关推荐
得寸进尺的鸡丝面5 分钟前
tomcat官网下载历史版本
java·tomcat
罗政8 分钟前
PDF书籍《手写调用链监控APM系统-Java版》第7章 插件与链路的结合:Tomcat插件实现
java·pdf·tomcat
程序猿毕设源码分享网16 分钟前
基于springboot校园招聘系统源码和论文
java·spring boot·后端
山山而川粤31 分钟前
美食推荐系统|Java|SSM|JSP|
java·开发语言·后端·学习·mysql
小小药33 分钟前
012-spring的注解开发
java·后端·spring
找了一圈尾巴35 分钟前
Wend看源码-Java-集合学习(Queue)
java·学习
#sakura37 分钟前
javaEE
java·开发语言·java-ee
wowing-1 小时前
Kotlin快速入门
开发语言·kotlin
AI人H哥会Java1 小时前
【Spring】基于XML的Spring容器配置——Bean的作用域
java·开发语言·后端·spring·架构
紧跟先前的步伐2 小时前
java常用类(下)
java·开发语言·算法