开发者

Maven: Include file defined in parent POM?

I have set up a parent POM for use by all my projects with standard configuration. I've been playing with the maven-java-formatter-plugin and using my own formatter config file. In the parent POM I've set this up:

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

But this requires that I include the formatter-config.xml in each project. What I'd like to somehow do is automatically retrieve/copy that file from some known location (possibly another project whose only purpose is to hold this file) into all the projects automagically during the build phase. I'm pretty sure there's a way to do this, but I can't come up with the right search terms.

EDIT (response to prunge)

I put the config file in a separate project (packaged as a jar) and added that as a dependency to my parent POM. However, when I try to build a project that makes use of the parent POM, I get this error:

[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]

It appears that the formatter-config.xml file is not being resolved from the classpath as per the formatter plugin page you referenced.

This is what I have; perhaps you开发者_运维技巧 can tell me where I went wrong:

CodeFormatter (builds a jar)
|-- pom.xml
|-- src
|   `-- main
|       `-- resources
|           `-- eclipse
|               `-- formatter-config.xml

Parent POM is same as above but have added new dependency:

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

No changes to the TestServlet project POM; it includes the parent POM:

<parent>
    <groupId>my.company</groupId>
    <artifactId>super-pom</artifactId>
    <version>1.0</version>
</parent>


See Multimodule Configuration example from the plugin site.

Essentially, you create a project which just has the formatter-config.xml file in it, build and deploy this project to your repository, then add this dependency to the plugin itself in your parent 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>

where in your buildutils project, the formatter-config.xml file will put into src/main/resources/eclipse/ directory.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜