我已经设置了一个父POM,供我所有使用标准配置的项目使用。我一直在玩maven-java-formatter-plugin并使用我自己的格式化程序配置文件。在父POM我设置了这个:
<build>
...
<!-- Format the code during process-sources -->
<plugin>
<groupId>com.googlecode.maven-java-formatter-plugin</groupId>
<artifactId>maven-java-formatter-plugin</artifactId>
<version>${formatter.version}</version>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>format</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- Use plugin to compiler config vice those in formatter config
file -->
<overrideConfigCompilerVersion>true</overrideConfigCompilerVersion>
<compilerSource>${jdk.version}</compilerSource>
<compilerCompliance>${jdk.version}</compilerCompliance>
<compilerTargetPlatform>${jdk.version}</compilerTargetPlatform>
<!-- Use Unix line endings -->
<lineEnding>LF</lineEnding>
<!-- The formatter config file -->
<configFile>${project.basedir}/formatter-config.xml</configFile>
</configuration>
</plugin>
</plugins>
</build>
但这要求我在每个项目中包含formatter-config.xml。我想以某种方式做的是在构建阶段自动从一些已知位置(可能是另一个目的是保存此文件的项目)将该文件检索/复制到所有项目中。我很确定有办法做到这一点,但我无法提出正确的搜索条件。
编辑(对prunge的回应)
我将配置文件放在一个单独的项目中(打包为jar)并将其作为依赖项添加到我的父POM中。但是,当我尝试构建一个使用父POM的项目时,我收到此错误:
[ERROR] Failed to execute goal com.googlecode.maven-java-formatter-plugin:maven-java-formatter-plugin:0.3.1:format (default) on project TestServlet: Config file [eclipse/formatter-config.xml] cannot be found: Could not find resource 'eclipse/formatter-config.xml'. -> [Help 1]
根据您引用的formatter插件页面,似乎没有从类路径中解析formatter-config.xml文件。
这就是我所拥有的;也许你可以告诉我哪里出错了:
CodeFormatter (builds a jar)
|-- pom.xml
|-- src
| `-- main
| `-- resources
| `-- eclipse
| `-- formatter-config.xml
父POM与上述相同,但添加了新依赖项:
<groupId>my.company</groupId>
<artifactId>super-pom</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
....
<dependencies>
<dependency>
<groupId>my.company</groupId>
<artifactId>code-formatter</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
...
TestServlet项目POM没有变化;它包括父POM:
<parent>
<groupId>my.company</groupId>
<artifactId>super-pom</artifactId>
<version>1.0</version>
</parent>
答案 0 :(得分:3)
请参阅插件网站的Multimodule Configuration example。
基本上,您创建一个项目,其中只包含formatter-config.xml
文件,构建并将此项目部署到您的存储库,然后将此依赖项添加到父POM中的插件本身
e.g。
<plugin>
<groupId>com.googlecode.maven-java-formatter-plugin</groupId>
<artifactId>maven-java-formatter-plugin</artifactId>
<version>${formatter.version}</version>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>format</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- Use plugin to compiler config vice those in formatter config
file -->
<overrideConfigCompilerVersion>true</overrideConfigCompilerVersion>
<compilerSource>${jdk.version}</compilerSource>
<compilerCompliance>${jdk.version}</compilerCompliance>
<compilerTargetPlatform>${jdk.version}</compilerTargetPlatform>
<!-- Use Unix line endings -->
<lineEnding>LF</lineEnding>
<!-- The formatter config file -->
<configFile>eclipse/formatter-config.xml</configFile>
</configuration>
<dependencies>
<dependency>
<groupId>com.myorg.buildutils</groupId>
<artifactId>my-eclipse-config</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</plugin>
在您的buildutils项目中,formatter-config.xml文件将放入src / main / resources / eclipse /目录。