使用Maven2,Eclipse风格组织导入? [英] Organize imports with Maven2, Eclipse-style?
问题描述
我对Java中的导入风格主题,但我确实希望尽可能减少我们的差异。我可以做什么?
我们使用Maven2进行构建;有没有可以帮助我的插件?一个Eclipse可以被抽出来变成了Maven插件?我目前使用的是 ImportScrubber ,并且遇到了其他一些单独做的事情。我真正寻找的是一个可以与构建集成的Maven插件。
除了上述内容,我将把ImportScrubber调用放入我的 .git / hooks / post-commit
。
Hybridlabs 美化者,在 OpenArchitectureWare 项目(一个开源生成器框架)正在做你正在寻找的内容。如博客条目所述,美化者可作为 Google Code project 及其文档描述了一个maven 2插件:
<插件>
< groupId> org.hybridlabs< / groupId>
< artifactId> maven-beautifier-plugin< / artifactId>
<执行>
< execution>
< goals>
< goal>美化 - 进口< / goal>
< / goals>
< / execution>
< / executions>
< configuration>
<! - 递归扫描* .java并美化导入 - >
< inputDirectory> $ {pom.basedir} /..& lt; / inputDirectory>
<! - outputDirectory> $ {pom.basedir} /..& lt; / outputDirectory>
< runBeautifier> true / runBeautifier>
< runJalopy> false< / runJalopy - >
< / configuration>
< / plugin>
源码树它不符合上面提到的 groupId
(这有点混乱),我在maven的公共存储库中找不到插件。
也许你会更加幸运的是AndroMDA插件库中提供的版本,如这个线程(插件确实存在于 http://team.andromda.org/maven2/ )。
插件是在
org.apache.maven.plugins.maven-beautifier-plugin
下。
它可以用简单的形式运行:
mvn beautifier:beautify-imports
。
也可以通过在< build>< plugins>
下添加插件声明
作为项目的一部分
pom运行。 :< plugin>
< groupId> org.apache.maven.plugins< / groupId>
< artifactId> maven-beautifier-plugin< / artifactId>
< version> 1.0< / version>
<执行>
< execution>
< goals>
< goal>美化 - 进口< / goal>
< / goals>
< / execution>
< / executions>
< configuration>
< inputDirectory> $ {pom.basedir} / target / src< / inputDirectory>
< / configuration>
< / plugin>
或联系项目的作者(例如通过 twitter 或邮件)。
I'm a lone Emacs user in a group that's hung up on Eclipse. Time and again, code diffs are made larger by imports that have been "organized" or "cleaned up" by Eclipse.
I don't have a strong opinion on the subject of import style in Java, but I do want to minimize our diffs. What can I do?
We use Maven2 for builds; is there a plugin that can help me? Can a piece of Eclipse be abstracted out & turned into a Maven plugin? I currently use ImportScrubber and have encountered a few other stand-alone pieces that do the same thing. What I'm really looking for is a Maven plugin that can integrate with the build.
Barring the above, I'll put an ImportScrubber invocation into my .git/hooks/post-commit
.
The Hybridlabs beautifier which is used internally in the openArchitectureWare project (an open source generator framework) is doing what you're looking for. As explained in this blog entry, the beautifier is available as a Google Code project and its documentation describes a maven 2 plugin:
<plugin>
<groupId>org.hybridlabs</groupId>
<artifactId>maven-beautifier-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>beautify-imports</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- Recursively scan for *.java and beautifies imports -->
<inputDirectory>${pom.basedir}/..</inputDirectory>
<!--outputDirectory>${pom.basedir}/..</outputDirectory>
<runBeautifier>true/runBeautifier>
<runJalopy>false</runJalopy-->
</configuration>
</plugin>
There is indeed a mojo in the source tree but it doesn't match the groupId
mentioned above (this is a bit confusing) and I've not been able to find the plugin in maven's public repository.
Maybe you'll be more lucky with the version available in AndroMDA plugin repository as documented in this thread (the plugin is indeed present in http://team.andromda.org/maven2/).
The plugin is under
org.apache.maven.plugins.maven-beautifier-plugin
. It can be run with the short form:mvn beautifier:beautify-imports
. It can also be run as part of a project pom by adding the plugin declaration under<build><plugins>
:<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-beautifier-plugin</artifactId> <version>1.0</version> <executions> <execution> <goals> <goal>beautify-imports</goal> </goals> </execution> </executions> <configuration> <inputDirectory>${pom.basedir}/target/src</inputDirectory> </configuration> </plugin>
Or contact the project's author (e.g. through twitter or by mail).
这篇关于使用Maven2,Eclipse风格组织导入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!