简体   繁体   English

使用 JDT Core 编译器构建 maven 项目

[英]Building maven projects with JDT Core compiler

I am a new Maven user.我是新的 Maven 用户。 I am aware that the default compiler which Maven uses to build its projects with is Javac.我知道 Maven 用于构建其项目的默认编译器是 Javac。 However, I want to use JDT Core compiler in order to build.但是,我想使用 JDT Core 编译器来构建。

I tried adding this plugin into my plugins in my root pom, but it doesn't work.我尝试将此插件添加到我的根 pom 中的插件中,但它不起作用。

<plugin>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.8.0</version>
  <configuration>
    <compilerId>eclipse</compilerId>
  </configuration>
  <dependencies>
    <dependency>
      <groupId>org.eclipse.jdt.core.compiler</groupId>
      <artifactId>ecj</artifactId>
      <version>4.4.2</version>
    </dependency>
  </dependencies>
</plugin>

would appreciate any help.将不胜感激任何帮助。

I got it working:我让它工作:

  1. Use the documented plugin/configuration style.使用记录在案的插件/配置样式。
  2. Adjust the version, that suits you best (I had "issues" with lower (than 2.8.8 ) and 2.9.0 versions).调整最适合您的版本(我遇到了低于(低于2.8.8 )和2.9.0版本的“问题”)。

like so:像这样:

<?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>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <build>
        <plugins> 
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <compilerId>eclipse</compilerId>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.codehaus.plexus</groupId>
                        <artifactId>plexus-compiler-eclipse</artifactId>
                        <version>2.8.8</version> <!-- => ecj.3.2.2 -->
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
</project>

with:和:

mvn clean compile -X

we get:我们得到:

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: C:\Program Files\NetBeans-12.5\netbeans\java\maven\bin\..
Java version: 16.0.2, vendor: Oracle Corporation, runtime: C:\Program 
Files\Java\jdk-16.0.2
Default locale: de_DE, platform encoding: UTF-8
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows
...
... 
-- end configuration --
Using compiler 'eclipse'.
Adding ...
CompilerReuseStrategy: reuseCreated
useIncrementalCompilation enabled
Stale source detected: ...
Changes detected - recompiling the module!
Classpath:
 ...
Source roots:
 ...\src\main\java
 ...\target\generated-sources\annotations
incrementalBuildHelper#beforeRebuildExecution
Using JSR-199 EclipseCompiler
ecj: using character set UTF-8
ecj command line: [-noExit, -preserveAllLocals, -g:lines,vars,source, -source, 1.6, -target, 1.6, -encoding, UTF-8, -warn:none, -d, ...\target\classes, -classpath, ...\target\classes;...\target\classes;]
ecj input source files: [C:\DEV\projects\...\Application.java]

incrementalBuildHelper#afterRebuildExecution
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time:  3.254 s
Finished at: 2021-11-18T18:03:02+01:00
------------------------------------------------------------------------

To use(try;;) an alternative ecj version, we can:要使用(try;;) 替代ecj版本,我们可以:

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.1</version>
    <configuration>
        <compilerId>eclipse</compilerId>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.codehaus.plexus</groupId>
            <artifactId>plexus-compiler-eclipse</artifactId>
            <version>2.8.8</version>
            <exclusions>
                <exclusion>
                    <groupId>org.eclipse.jdt</groupId>
                    <artifactId>ecj</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jdt</groupId>
            <artifactId>ecj</artifactId>
            <version>3.27.0</version> <!-- 09/15/2021 -->
        </dependency>
    </dependencies>
</plugin>    

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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