在maven组件中使用eclipse编译器

发布于 2024-11-17 04:11:55 字数 1453 浏览 6 评论 0原文

我正在开发一个相当大的 Maven 项目,并使用 Eclipse 使用 Java 进行开发。

为了节省编译时间,我想Maven和Eclipse共享 同样的目标,我成功做到了。但是当我编译时 Maven、Eclipse 缺少一些放入字节码中的东西,所以它 重新编译所有内容(据我所知)。我在这里谈论的是“自动构建”功能,因此并不是 Eclipse 将构建委托给 Maven。

为了解决这个问题,我想我应该要求 Maven 使用与 Eclipse 相同的编译器。 在网上进行一些搜索后,我发现我可以将其添加到顶部 pom 中:

<build>
...
<plugins>
...
<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-compiler-plugin</artifactId>
   <configuration>
           <compilerId>eclipse</compilerId>
           <source>1.5</source>
           <target>1.5</target>
           <optimize>true</optimize>
   </configuration>
   <dependencies>
           <dependency>
                   <groupId>org.codehaus.plexus</groupId>
                   <artifactId>plexus-compiler-eclipse</artifactId>
                   <version>1.8.1</version>
           </dependency>
   </dependencies>
</plugin>
</plugins>
</build>

这似乎可行,但构建很快就会失败,并出现大量错误 错误,而 javac 则成功。 我不确定为什么,但似乎存在一些冲突 事实上,失败的 Java 文件是生成的文件。

所以我想我可以尝试仅使用 Eclipse 编译器 我正在开发的组件(它没有那种生成的 文件)。我在组件的 pom 中添加了上面的代码片段,但是当 构建到达我的组件时,出现以下错误:

没有这样的编译器“eclipse”

我还尝试在 顶部 pom 中列出了依赖项,但出现同样的错误。

你知道我想做的事情是否可能吗?有什么提示我该怎么做吗?

I am working on a fairly big Maven project, and develop in Java with Eclipse.

To save compilation time, I would like Maven and Eclipse to share
the same target, which I managed to do. However when I compile with
Maven, Eclipse lacks some stuff that it puts in the bytecode, so it
recompiles everything (from what I understand). I am talking about the "build automatically" feature here, so it is not Eclipse delegating the build to Maven.

To solve this, I thought I would ask Maven to use the same compiler as Eclipse.
After some search on the web, I found out I could add this in the top pom:

<build>
...
<plugins>
...
<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-compiler-plugin</artifactId>
   <configuration>
           <compilerId>eclipse</compilerId>
           <source>1.5</source>
           <target>1.5</target>
           <optimize>true</optimize>
   </configuration>
   <dependencies>
           <dependency>
                   <groupId>org.codehaus.plexus</groupId>
                   <artifactId>plexus-compiler-eclipse</artifactId>
                   <version>1.8.1</version>
           </dependency>
   </dependencies>
</plugin>
</plugins>
</build>

This seems to work, but the build fails fairly quickly with lots of
errors, while it succeeds with javac.
I'm not sure why, but it seems that there is some conflicts linked to
the fact the failing Java files are generated files.

So I thought I could try to use the Eclipse compiler only for the
component I am working on (which does not have that kind of generated
files). I added the above snippet in the pom of my component, but when
the build reaches my component, the following error is raised:

No such compiler 'eclipse'

I also tried to add the plexus-compiler-eclipse dependency in the
dependencies listed in the top pom, but same error.

Do you know if what I am trying to do is possible? Any hint of how I can do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

生活了然无味 2024-11-24 04:11:55

这是一个与 Maven 多模块项目相关的老问题:
http://jira.codehaus.org/browse/MCOMPILER-165

This is an old open issue related to maven multimodule projects:
http://jira.codehaus.org/browse/MCOMPILER-165

荭秂 2024-11-24 04:11:55

我猜你的问题是由于 eclipse 项目和 maven pom 不同步引起的。我建议您使用 m2eclipse 插件 来保持 Maven 和 Eclipse 同步。这将使用 POM 作为“主”配置来配置您的 eclipse 项目。

我认为您不需要专门配置要使用的编译器,但您应该像您已经在做的那样配置 maven-compiler-plugin 。

I would guess that your issues arise from the eclipse project and maven pom not being in synch. I would suggest that you use the m2eclipse plugin to keep maven and eclipse in synch. This will configure your eclipse project by using the POM as the 'master' configuration.

I don't think you need to specifically configure what compiler to use, but you should configure the maven-compiler-plugin as you are already doing.

盛夏已如深秋| 2024-11-24 04:11:55

确保您使用最新版本的 maven-compiler-plugin (现在为 2.3.2,查看此页面 - 它是“全名”或右上角的小版本信息)。

除此之外,配置应该可以工作。您也可以尝试使用最新的 1.8.4 版本的 plexus-compiler-eclipse

除此之外,您需要了解 Maven 有多种类型的依赖项。就您而言,有两个很有趣:构建时和插件依赖项。

前者收集在 dependencies 元素中,而后者必须位于 pluginManagement 元素 中。将插件添加到构建时类路径不会达到您想要的效果。

Make sure you use the latest version of the maven-compiler-plugin (2.3.2 right now, see this page - it's "Full name" or the little version info in the top right corner).

Apart from this, the configuration should work. You can try with the latest 1.8.4 version of the plexus-compiler-eclipse, too.

Apart from that, you need to understand that Maven has several types of dependencies. In your case, two are interesting: Build-time and plugin dependencies.

The former are collected in the dependencies element while the latter must be in a pluginManagement element. Adding a plugin to the build time classpath will not have the effect you want.

夜还是长夜 2024-11-24 04:11:55

我不是 100% 确定你想在这里实现什么,但这听起来是一个坏主意。首先,您应该将 Eclipse 配置为在您的系统上使用 SDK,并且 Maven 应该使用相同的东西。所以我不明白为什么你认为 Eclipse 正在向字节码添加一些 Maven 不会给出的东西,无论如何它们都使用相同的编译器。

其次,我不会尝试在 Maven 构建中使用任何 Eclipse 组件。它们被设计为在 Eclipse IDE 中工作,因此让它们在 Eclipse 之外工作通常会遇到很多问题。我已经看到它完成了,但它是一个黑客并且没有产生很好的结果。

第三,如果您在 Maven 构建中遇到性能问题(并不罕见),您可以采取一些措施。首先分解构建并弄清楚时间都花在哪里了。我的经验是,通常问题不是编译。以下是我所看到的导致构建速度减慢的因素的列表:

  • 质量测试不佳。通常启动集成测试很慢,并且与实际上作为集成运行的单元测试混合在一起。

  • 科贝尔图拉。很棒的工具,但由于 Maven 的工作方式,Cobertura 插件必须再次运行从资源到编译的所有阶段。我曾经通过编写一个插件来停止运行测试,直到它们由 cobertura 阶段运行,从而将 Maven 的长构建时间缩短了 40%。

  • 过度建设。 IE。包括基本上永远不会改变的子模块。更好的选择是仅在必要时创建包含这些子模块的配置文件,或者将其分解为完全独立的构建。

  • 长时间的集成测试。如果集成测试需要很长时间,请考虑将它们放入 CI 服务器上的不同配置文件和不同构建中。然后,您的主构建可以更快地进行,从而使开发人员能够更快地恢复工作,同时集成测试可以运行得更少。

  • 最后 - 承认 Maven 是一个性能消耗者并转向更快的东西。 Ant 可能仍然是最快的,但设置起来很痛苦,因为您必须手动配置所有内容。我建议尝试 Grandle 因为它修复了 Ant 和 Maven 都存在的许多问题。虽然说实话,我个人并没有对其做过任何性能测试。但它确实为您提供了 Maven 所没有的控制级别。

I'm not 100% sure what you are trying to achieve here but it sounds like a bad idea. Firstly, you should have Eclipse configured to being use a SDK on your system and Maven should be using the same thing. So I don't understand why you think Eclipse is adding something to the byte code which Maven would not be given they are both using the same compiler anyway.

Secondly I would not be trying to use any Eclipse components in a maven build. They are design to work within the Eclipse IDE so getting them working outside of that is usually fraught with problems. I've seen it done, but it was a hack and didn't produce very good results.

Thridly if you are having performance problems with a Maven build (not uncommon), there are a few things you can do. Firstly break down the build and work out where the time is going. My experience is that usually it's not the compilation that is the problem. Here's a list of things that I've seen slow down builds:

  • Poor quality tests. Usually slow to start up integration tests compounded with tests that are actually unit tests being run as integrations.

  • Cobertura. Great tool but because of the way Maven works, the Cobertura plugin has to run all the phases from resources to compilation again. I once shaved 40% off the during of a long Maven build by writing a plugin to stop tests being run until they where being run by the cobertura phase.

  • Over building. ie. including submodules that basically never change. Better choice is to create a profile that includes these sub mobules only when necessary or break then out to a completely seperate build.

  • Long integration testing. If the integration tests take a long time, consider putting them into a different profile and a different build on the CI server. Then your main build can go faster allowing developers to get back to work sooner, whilst the integration tests can run less often.

  • Finally - admit that Maven is a performance hog and move to something faster. Ant is probably still the fastest but a pain to setup because you have to manually configure everything. I'd suggest trialing Grandle as it fixes a lot of the issues that both Ant and Maven have. Although to be honest, I have not personally done any performance testing on it. But it does give you a level of control that Maven does not.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文