使用Eclipse风格的Maven2组织导入?

时间:2021-09-04 13:53:04

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.

我是一个独立的Emacs用户,在一个挂在Eclipse上的组中。通过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?

我对Java中的导入样式主题没有强烈的意见,但我确实希望尽量减少差异。我能做什么?

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.

我们使用Maven2进行构建;有插件可以帮助我吗?可以将一块Eclipse抽象出来并变成一个Maven插件吗?我目前使用的是ImportScrubber,并且遇到过其他一些独立的部件,它们也做同样的事情。我真正想要的是一个可以与构建集成的Maven插件。

Barring the above, I'll put an ImportScrubber invocation into my .git/hooks/post-commit.

除非上述内容,否则我会将ImportScrubber调用放入我的.git / hooks / post-commit中。

4 个解决方案

#1


2  

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:

在openArchitectureWare项目(开源生成器框架)内部使用的Hybridlabs美化器正在寻找您正在寻找的东西。正如本博客文章中所述,美化器可作为Google Code项目使用,其文档描述了maven 2插件:

<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.

源树中确实存在一个mojo,但它与上面提到的groupId不匹配(这有点令人困惑)而且我无法在maven的公共存储库中找到该插件。

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/).

也许你会更幸运的是AndroMDA插件库中提供的版本,如此线程中所述(该插件确实存在于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>:

该插件位于org.apache.maven.plugins.maven-beautifier-plugin下。它可以使用简短形式运行:mvn beautifier:beautify-imports。它也可以通过在 下添加插件声明作为项目pom的一部分运行:

<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).

或者联系项目的作者(例如通过推特或邮件)。

#2


1  

I think all of you (Eclipse, Emacs or whatever users) should use something like Jalopy which supports both Eclipse and Maven. This way it becomes irrelevant where the code was modified as long as it has been run through pretty-printer as part of checking code in. Said that - I'm not sure if Jalopy supports organizing imports beyond sorting these up

我认为你们所有人(Eclipse,Emacs或其他任何用户)都应该使用像Jalopy这样的东西来支持Eclipse和Maven。这样,只要在代码检查过程中通过漂亮的打印机运行代码就会变得无关紧要。说 - 我不确定Jalopy是否支持组织导入而不是对它们进行排序

#3


0  

Does your shop have code standards for how imports should be organized? If so then you are out of luck. Minimizing diffs is a small sacrifice to make towards incremental code improvement.

您的商店是否有关于如何组织进口的代码标准?如果是这样,那你就不走运了。最小化差异是实现增量代码改进的一小部分牺牲。

#4


0  

I have also found an ImportScrubber plugin. Can't as of yet attest to its quality.

我还找到了一个ImportScrubber插件。不能证明它的质量。

#1


2  

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:

在openArchitectureWare项目(开源生成器框架)内部使用的Hybridlabs美化器正在寻找您正在寻找的东西。正如本博客文章中所述,美化器可作为Google Code项目使用,其文档描述了maven 2插件:

<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.

源树中确实存在一个mojo,但它与上面提到的groupId不匹配(这有点令人困惑)而且我无法在maven的公共存储库中找到该插件。

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/).

也许你会更幸运的是AndroMDA插件库中提供的版本,如此线程中所述(该插件确实存在于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>:

该插件位于org.apache.maven.plugins.maven-beautifier-plugin下。它可以使用简短形式运行:mvn beautifier:beautify-imports。它也可以通过在 下添加插件声明作为项目pom的一部分运行:

<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).

或者联系项目的作者(例如通过推特或邮件)。

#2


1  

I think all of you (Eclipse, Emacs or whatever users) should use something like Jalopy which supports both Eclipse and Maven. This way it becomes irrelevant where the code was modified as long as it has been run through pretty-printer as part of checking code in. Said that - I'm not sure if Jalopy supports organizing imports beyond sorting these up

我认为你们所有人(Eclipse,Emacs或其他任何用户)都应该使用像Jalopy这样的东西来支持Eclipse和Maven。这样,只要在代码检查过程中通过漂亮的打印机运行代码就会变得无关紧要。说 - 我不确定Jalopy是否支持组织导入而不是对它们进行排序

#3


0  

Does your shop have code standards for how imports should be organized? If so then you are out of luck. Minimizing diffs is a small sacrifice to make towards incremental code improvement.

您的商店是否有关于如何组织进口的代码标准?如果是这样,那你就不走运了。最小化差异是实现增量代码改进的一小部分牺牲。

#4


0  

I have also found an ImportScrubber plugin. Can't as of yet attest to its quality.

我还找到了一个ImportScrubber插件。不能证明它的质量。