在pom.xml中包含另一个xml文件

3

我正在尝试在 pom.xml (maven) 中包含xml文件。 我的pom.xml看起来像这样

<?xml version="1.0" encoding="UTF-8"?>
<project>
<!-- <xi:include href="minify.xml" xmlns:xi="http://www.w3.org/2003/XInclude"/>
 -->  <modelVersion>4.0.0</modelVersion>
  <groupId>myproject</groupId>
  <artifactId>myproject</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <description></description>
  <build>
    <plugins>

      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source>1.5</source>
          <target>1.5</target>
        </configuration>
      </plugin>
    <!-- include plugin tag from other xml file -->
// I would like maintain one seperate xml file to hold all plugin tags (to reduce pom.xml //file content.
</plugins>

我正在使用"com.samaxes.maven"压缩CSS和JS文件。 但是我的CSS和JS文件存储在许多不同的文件夹中。我需要重复包含以下标记:

<plugin>
    <groupId>com.samaxes.maven</groupId>
    <artifactId>minify-maven-plugin</artifactId>
    <version>1.7.4</version>
    <executions>
        <execution>
            <id>default-minify-1</id>
            <configuration>
                   <charset>utf-8</charset>
                   <jsEngine>CLOSURE</jsEngine>
                   <skipMerge>true</skipMerge>
                   <nosuffix>true</nosuffix>
                  <!--   <skipMinify>true</skipMinify>   -->   <!--skips already minfied css fiels -->

                    <cssSourceDir>inc/one/css</cssSourceDir>
                   <cssTargetDir>inc/one/css/mini</cssTargetDir>
                   <cssSourceIncludes>
                      <cssSourceInclude>*.css</cssSourceInclude>
                   </cssSourceIncludes>

                    <jsSourceDir>proj/platform/common/js/</jsSourceDir>
                   <jsTargetDir>proj/platform/common/js/mini</jsTargetDir>
                   <jsSourceIncludes>
                     <jsSourceInclude>*.js</jsSourceInclude>
                   </jsSourceIncludes>
                   <closureCreateSourceMap>true</closureCreateSourceMap>
            </configuration>
            <goals>
                <goal>minify</goal>
            </goals>
        </execution>
    </executions>
 </plugin>

我在谷歌上搜索了包含多个目录的可能方法,然后决定通过重复上面的代码片段来包含所有目录。但后来想将所有mifiy include分离到另一个xml文件中。我正在寻找一些方法将xml文件包含在<include>标记内。

2个回答

1
另一种做法是使用迭代器 Maven 插件。它具有遍历文件夹并为每个项目调用另一个插件的能力。
对于您的情况,可以这样做。
<plugin>
  <groupId>com.soebes.maven.plugins</groupId>
  <artifactId>iterator-maven-plugin</artifactId>
  <version>0.5.1</version>
  <executions>
    <execution>
      <phase>package</phase>
      <goals>
        <goal>iterator</goal>
      </goals>
      <configuration>
        <folder>whatever/your/folder/is</folder>
        <pluginExecutors>
          <pluginExecutor>
            <plugin>
              <groupId>com.samaxes.maven</groupId>
              <artifactId>minify-maven-plugin</artifactId>
              <version>1.7.4</version>
            </plugin>
            <goal>minify</goal>
            <executions>
              <execution>
                <id>default-minify-1</id>
                <configuration>
                  <charset>utf-8</charset>
                  <jsEngine>CLOSURE</jsEngine>
                  <skipMerge>true</skipMerge>
                  <nosuffix>true</nosuffix>
                  <!--   <skipMinify>true</skipMinify>   -->   <!--skips already minfied css fiels -->

                  <cssSourceDir>@item@/inc/one/css</cssSourceDir>
                  <cssTargetDir>@item@/inc/one/css/mini</cssTargetDir>
                  <cssSourceIncludes>
                    <cssSourceInclude>*.css</cssSourceInclude>
                  </cssSourceIncludes>

                  <jsSourceDir>@item@/proj/platform/common/js/</jsSourceDir>
                  <jsTargetDir>@item@/proj/platform/common/js/mini</jsTargetDir>
                  <jsSourceIncludes>
                    <jsSourceInclude>*.js</jsSourceInclude>
                  </jsSourceIncludes>
                  <closureCreateSourceMap>true</closureCreateSourceMap>
                </configuration>
              </execution>
            </executions>
          </pluginExecutor>
        </pluginExecutors>
      </configuration>
    </execution>
  </executions>
</plugin>

0

我认为这不是Maven应该使用的方式...

你可以创建一个包含所有全局插件配置的父级pom.xml文件,并将其放在pluginManagement部分中。然后,在所有子级pom.xml中,你可以通过id“default-minify-1”激活已配置的执行。但是,配置只需在父级pom.xml中完成一次。

请参见在多模块maven构建中重用ant-snippets


谢谢@StefanHeimberg。现在我正在使用YUI压缩器,解决了我的问题。 - ULLAS K

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接