Eclipse Maven编译器不支持编译器插件编译器 [英] Eclipse maven compiler not supporting compiler-plugin compilerArgs

查看:333
本文介绍了Eclipse Maven编译器不支持编译器插件编译器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一组Java模块项目(使用JDK11).

We have a collection of Java module projects (using JDK11).

我们的集成测试有一个单独的项目.该项目需要能够访问主应用程序项目以运行其测试,但是我们不想向主应用程序模块添加导出,因为只有在运行测试时才需要导出.

There is a separate project for our integration tests. This project needs to be able to access the main application project to run its tests, but we don't want to add an export to the main application module because it's only needed when we're running our tests.

解决方案是在集成测试项目中使用 compilerArgs 添加导出:

The solution has been to add the export using compilerArgs in our integration test project:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${maven.compiler.plugin.version}</version>
            <configuration>
                <release>${java.version}</release>
                <parameters>true</parameters>
                <showDeprecation>true</showDeprecation>
                <showWarnings>true</showWarnings>
                <compilerArgs>
                    <arg>--add-exports</arg>
                    <arg>com.example.application/com.example.application=com.example.integration_tests</arg>
                </compilerArgs>
            </configuration>
        </plugin>
    </plugins>
</build>

这适用于命令行mvn clean install.但是可悲的是,它对日食不起作用. 不管出于什么原因,eclipse都会忽略这些builderArgs并不断给出错误消息,指出主应用程序类不可访问.

This works for a command line mvn clean install. But sadly it doesn't work for eclipse. For whatever reason eclipse ignores these compilerArgs and keeps giving errors that the main application class is not accessible.

是否有某种方法可以强制Eclipse使用这些CompilerArgs?还是Eclipse尚未涵盖的模块系统的某些方面?

Is there some way to force eclipse to use these compilerArgs? Or is this some aspect of the module system that Eclipse hasn't gotten around to covering yet?

推荐答案

对于.classpath文件中的Maven依赖项,可以通过替换手动设置--add-exports编译器参数 strong>

The --add-exports compiler argument can be set manually for Maven dependencies in the .classpath file by replacing

<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
    <attributes>
        <attribute name="maven.pomderived" value="true"/>
    </attributes>
</classpathentry>

使用

<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
    <attributes>
        <attribute name="add-exports" value="com.example.application/com.example.application=com.example.integration_tests"/>
        <attribute name="maven.pomderived" value="true"/>
    </attributes>
</classpathentry>

不幸的是,右键单击项目,然后选择 Maven>更新项目... 会反转手动设置.

Unfortunately, right-clicking the project and choosing Maven > Update Project... reverses the manual settings.

请参阅: Eclipse错误543631-Eclipse-Maven-JPMS (如果您想使用此功能,请在此处进行评论并投票)

See: Eclipse bug 543631 - Eclipse - Maven - JPMS (please comment and vote there if you would like to have this feature)

要在更新项目后恢复手动设置,可以在更新项目之前用其版本替换.classpath文件.

To restore your manual settings after updating the project, you can replace the .classpath file with its version before updating the project.

对于使用JPMS但访问模块内部内容的测试代码,请考虑以下单独项目的替代方案:

Please consider the following alternatives to a separate project for test code that uses JPMS but accesses internal stuff of a module:

  • 将测试代码放入src/test/java/中,而不是放入单独的项目中(访问内部表示这是单元测试而不是集成测试)
  • 在单独的(集成)测试项目中,不访问所需模块的内部内容
  • 请勿在单独的(集成)测试项目中使用JPMS
  • Put the test code into src/test/java/ instead of into a separate project (accessing internals indicates that it is an unit test rather than an integration test)
  • In the separate (integration) test project do not access interal stuff of required module
  • Do not use JPMS in the separate (integration) test project

这篇关于Eclipse Maven编译器不支持编译器插件编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆