标签: maven-compiler-plugin

maven-compiler-plugin在检查过时源时会考虑依赖吗?

Ant的依赖任务允许重新编译Java源代码,如果它的任何依赖项(引用的类,而不是模块依赖项)已被修改.我快速浏览了一下org.apache.maven.plugin.CompilerMojoorg.codehaus.plexus.compiler.util.scan.StaleSourceScanner,根据它的外观,它们根本不考虑依赖关系.如果源代码的时间戳比类文件的时间戳更新(加上一些增量值),则看起来好像重新编译了源代码.

我是否遗漏了任何东西,或者是Maven无视源代码没有改变但依赖性的情况(因此它们都需要重新编译)?

java dependencies maven maven-compiler-plugin

6
推荐指数
1
解决办法
393
查看次数

使用javac时出错:"javac:invalid flag:-s"

我正在尝试指定另一个版本的JDK maven-compiler-plugin.当-target-source参数设置为1.5时,一切正常.但是当我尝试使用1.6 JDK时,maven报告错误.有人遇到过这个问题吗?

错误:

执行javac失败,但无法解析错误:javac:invalid flag:-s用法:javac可能的选项包括:-g生成所有调试信息-g:none生成无调试信息

谢谢.

javac maven maven-compiler-plugin

6
推荐指数
1
解决办法
1万
查看次数

带有Java 8补丁的Eclipse 4.3.2无法识别源级别1.8

我正在使用带有Java 8补丁的 Eclipse 4.3.2 ,以及m2e和Subclipse,完全更新到所有版本的最新版本.

我为我们的项目进入Maven POM并将maven-compiler-plugin更改为:

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
    <source>1.8</source>
    <target>1.8</target>
Run Code Online (Sandbox Code Playgroud)

我更新了所有我的Maven项目,试图做一个完整的清理和构建.各处都有错误.暂时忽略内部编译器错误,我看到的错误是:

Syntax error, static imports are only available if source level is 1.5 or greater
Run Code Online (Sandbox Code Playgroud)

我正在运行Java 1.8 ---为什么我收到此消息?m2e应该受到责备吗?maven-compiler-plugin?或者Eclipse Java 1.8支持还没有为黄金时间做好准备?

eclipse maven java-8 m2e maven-compiler-plugin

6
推荐指数
2
解决办法
2852
查看次数

使用maven-compiler-plugin排除包适用于一个包,但不适用于另一个包

我的项目有以下包结构:

src/
  com.my.app.school.course
    -Course.java
    ...

  com.my.app.school.course.free
    -CourseFree.java  
Run Code Online (Sandbox Code Playgroud)

我使用Maven来构建项目,在我的pom.xml中,我定义了maven-compiler-plugin来测试排除包含所有java类的包.

我首先尝试以下方式排除com.my.app.school.course.free:

<build>
   <plugins>
       <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <excludes>
                    <exclude>**/com/my/app/school/course/free/*</exclude>
                </excludes>
             </configuration>
        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

有用!我的意思是在运行之后mvn clean install,target/classes /下的最终构建没有包com/my/app/school/course/free.

然后,我试图排除包com.my.app.school.course.我只需用值替换上面的<exclude>标记<exclude>**/com/my/app/school/course/*</exclude>.我认为它应该也可以,但它不会!在target/classes /下我看到所有包,不包括任何包.为什么?

我想要实现的是排除包com.my.app.school.course但保留pacakge com.my.app.school.course.free,如何实现这一目标?

========更新========

我觉得这可能是因为我试图排除的包包含已在其他包中使用的java类.我会核实我的猜测.

java maven-3 maven maven-compiler-plugin

6
推荐指数
1
解决办法
1万
查看次数

Maven 构建失败 - 编译器插件

我正在尝试在 Maven 中构建一个项目,但遇到以下错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project webgoat-container: Fatal error compiling: java.lang.ExceptionInInitializerError: Unable to make field private com.sun.tools.javac.processing.JavacProcessingEnvironment$DiscoveredProcessors com.sun.tools.javac.processing.JavacProcessingEnvironment.discoveredProcs accessible: module jdk.compiler does not "opens com.sun.tools.javac.processing" to unnamed module @5d01a2eb -> [Help 1]
Run Code Online (Sandbox Code Playgroud)

项目的pom.xml为:

<modelVersion>4.0.0</modelVersion>
<groupId>org.owasp.webgoat</groupId>
<artifactId>webgoat-parent</artifactId>
<packaging>pom</packaging>
<version>8.2.1-SNAPSHOT</version>

<name>WebGoat Parent Pom</name>
<description>Parent Pom for the WebGoat Project. A deliberately insecure Web Application</description>
<inceptionYear>2006</inceptionYear>
<url>https://github.com/WebGoat/WebGoat</url>

<organization>
    <name>OWASP</name>
    <url>https://github.com/WebGoat/WebGoat/</url>
</organization>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.4.3</version>
</parent>

<licenses>
    <license>
        <name>GNU General Public License, version 2</name>
        <url>https://www.gnu.org/licenses/gpl-2.0.txt</url>
    </license>
</licenses> …
Run Code Online (Sandbox Code Playgroud)

java maven maven-compiler-plugin

6
推荐指数
4
解决办法
8448
查看次数

Maven中eclipse编译器的参数

在独立的Eclipse Java编译器中,我可以通过命令行属性(如下面的存根所示)以XML登录编译信息:

java -jar ecj-4.3.2.jar -log compile.xml <classpath,files>
Run Code Online (Sandbox Code Playgroud)

但是,当我将avenus-compiler-plugin与plexus-compiler-eclipse一起使用时,似乎无法将此参数传递给编译器,并且我不确定其原因,即插件的编译器是否为另一个编译器,它不会不会产生新进程(我什至尝试过可执行参数)或其他原因。

这是pom.xml部分:

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-compiler-plugin</artifactId>
   <version>3.1</version>
   <configuration>
      <compilerId>eclipse</compilerId>
      <forceJavacCompilerUse>true</forceJavacCompilerUse>
      <!--<compilerArgument> -log compile.xml </compilerArgument>-->
      <compilerArgs>
        <arg>-log</arg>
        <arg>compile.xml</arg>
      </compilerArgs>
      <fork>true</fork>
      <verbose>true</verbose>
      <showDeprecation>true</showDeprecation>
      <showWarnings>true</showWarnings>
   </configuration>
   <dependencies>
      <dependency>
         <groupId>org.codehaus.plexus</groupId>
         <artifactId>plexus-compiler-eclipse</artifactId>
         <version>2.3</version>
      </dependency>
   </dependencies>
</plugin>
Run Code Online (Sandbox Code Playgroud)

java eclipse maven eclipse-jdt maven-compiler-plugin

5
推荐指数
1
解决办法
888
查看次数

当指定 fork=true 时,maven-compiler-plugin 不进行注释处理?

maven-compiler-plugin在 Maven 项目中使用它对我的代码执行注释处理。在我添加配置选项之前它一直有效<fork>true</fork>

pom.xml文件具有以下内容:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>2.5.1</version>
  <dependencies>
    <!-- Add dependency on the annotation processor -->
    <dependency>
      <groupId>x.y.z</groupId>
      <artifactId>my-processor</artifactId>
      <version>1.0</version>
    </dependency>
  </dependencies>
  <configuration>
    <source>1.7</source>
    <target>1.7</target>
  </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

my -processor-1.0.jar文件包含META-INF/services/javax.annotation.processing.Processor文件,以便编译javac器在运行时可以发现它。

当我使用此配置运行mvn cleancompile时,我看到注释处理器运行并且生成的代码按预期放入target\ generated-sources\annotations目录中。

但是,如果我<fork>true</fork>向插件配置添加一个选项,那么我会观察到注释处理器不会运行,并且target\ generated-sources\annotations目录中不存在任何代码。

我在maven-compiler-plugin2.5.1、3.0 和 3.1 版本中尝试过此操作(对于 3.x 版本,我必须<forceJavaCompilerUser>true</forceJavaCompilerUser>在配置中添加一个选项,以便能够发现注释处理器 jar)。

我还尝试显式指定注释处理器:

<configuration>
  ...
  <annotationProcessors>
    <annotationProcessor>x.y.z.MyProcessor</annotationProcessor>
  </annotationProcessors>
  ...
</configuration>
Run Code Online (Sandbox Code Playgroud)

同样,对于版本 2.5.1、3.0 和 3.1,如果配置选项未指定分叉,则将调用注释处理器。当<fork>true</fork>指定选项时,注释处理器将不会运行。

我还在依赖项x.y.z:my_processor之外添加了依赖项 …

annotations javac maven maven-compiler-plugin

5
推荐指数
1
解决办法
5255
查看次数

将 Maven Compiler Plugin 与 Eclipse Compiler 和 Lombok 结合使用

有没有办法在 ECJ 中编译 lomboked 代码而不将 lombok 设置为 maven 进程的javaaagent

下面的代码片段仅在我使用 lombok 作为代理运行 mvn 时才有效

<profile>
    <id>ecj</id>
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <compilerId>eclipse</compilerId>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>org.codehaus.plexus</groupId>
                            <artifactId>plexus-compiler-eclipse</artifactId>
                            <version>2.8-SNAPSHOT</version>
                        </dependency>
                        <dependency>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                            <version>1.16.8</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</profile>
Run Code Online (Sandbox Code Playgroud)

MAVEN_OPTS=-javaagent:lombok.jar mvn -P ecj 结果编译成功。

然而,运行只会mvn -P ecj产生通常的非龙目岛错误,例如:__ cannot be resolved to a type

我尝试使用com.reubenpeeris.maven:lombok-eclipse-compiler:1.3 但失败了Compilation failure Unrecognized option: target/generated-sources/annotations,我认为这意味着这个编译器太旧了。

我也尝试添加

<fork>true</fork>
<compilerArgs>
    <arg>-javaagent:lombok.jar</arg>
</compilerArgs>
Run Code Online (Sandbox Code Playgroud)

但它似乎没有任何效果。

eclipse maven lombok maven-compiler-plugin

5
推荐指数
1
解决办法
1791
查看次数

如何将额外的类路径依赖项传递给 maven 中的 testCompile 阶段

我想使用一些外部 jar 依赖项编译测试文件,这些依赖项不会出现在 pom.xml 的依赖项标记中。有没有办法通过配置。像这样的东西——

<plugin>
  <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
    <source>1.5</source>
    <target>1.5</target>
  </configuration>
  <executions>
    <execution>
      <id>test-compile</id>
      <configuration>
        <classPathElements>
            <classPathElement>somejar.jar</classPathElement>
        </classPathElements>
      </configuration>
    </execution>

  </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

java maven maven-compiler-plugin

5
推荐指数
1
解决办法
1362
查看次数

maven-comiler-plugin:编译致命错误:错误:不支持发布版本 17

我尝试使用 maven 创建一个非常简单的 JavaFX 项目,并使用 GitHub actions 从中构建一个 Linux 包。这是工作流程文件:

# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: Linux Client

on:
  workflow_dispatch:
  push:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - name: Set up JDK 17
        uses: actions/setup-java@v2
        with:
          java-version: '17'
          distribution: 'temurin'
      - name: Debug
        run: mvn -version
      - name: Build with Maven
        run: sudo mvn -e -B install --file pom.xml
      - name: Upload DEB …
Run Code Online (Sandbox Code Playgroud)

java maven maven-compiler-plugin github-actions

5
推荐指数
1
解决办法
3万
查看次数