Maven编译时,编译插件顺序问题出错

本文探讨了在Maven项目中混合使用Kotlin与Java时的配置问题,详细解析了如何正确设置编译插件以避免编译错误。通过调整编译阶段和绑定目标,确保Kotlin和Java代码可以顺利编译。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本人做kotlin与Java混合项目

 <build>
    <plugins>
      <plugin>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-maven-plugin</artifactId>
        <version>${kotlin.version}</version>
        <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>
        <configuration>
          <jvmTarget>1.8</jvmTarget>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <executions>
              <execution>
                  <id>compile</id>
                  <phase>compile</phase>
                  <goals>
                      <goal>compile</goal>
                  </goals>
              </execution>
              <execution>
                  <id>testCompile</id>
                  <phase>test-compile</phase>
                  <goals>
                      <goal>testCompile</goal>
                  </goals>
              </execution>
          </executions>
      </plugin>
      <plugin>
        <groupId>org.asciidoctor</groupId>
        <artifactId>asciidoctor-maven-plugin</artifactId>
        <version>1.5.6</version>
        <dependencies>
          <dependency>
            <groupId>org.asciidoctor</groupId>
            <artifactId>asciidoctorj-pdf</artifactId>
            <version>1.5.0-alpha.10.1</version>
          </dependency>
          <dependency>
            <groupId>org.jruby</groupId>
            <artifactId>jruby-complete</artifactId>
            <version>1.7.21</version>
          </dependency>
        </dependencies>
        <configuration>
          <sourceDirectory>src/main/doc/adoc</sourceDirectory>
          <outputDirectory>src/main/doc/pdf</outputDirectory>
          <backend>pdf</backend>
          <sourceHighlighter>coderay</sourceHighlighter>
          <attributes>
            <toc>left</toc>
          </attributes>
        </configuration>
      </plugin>
    </plugins>
  </build>

指定kotlin编译插件在前,maven编译插件再后. 编译出错。问题分析,maven插件编译在前。无法识别kotlin代码。故出错

问题出在maven <phase>compile</phase> 。编译阶段。

生命周期 总共有 以下。我们可以将kotlin插件生命周期指定为compile之上一种即可。 goal 绑定到phase(compile) 之上

validate
initialize
generate-sources
process-sources
generate-resources
process-resources
compile
process-classes
generate-test-sources
process-test-sources
generate-test-resources
process-test-resources
test-compile
process-test-classes
test
prepare-package
package
pre-integration-test
integration-test
post-integration-test
verify
install
deploy
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值