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

标签 xml maven

我正在尝试将 xml 文件包含在 pom.xml (maven) 中。 我的 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 包含到其他 xml 文件中。我正在寻找将 xml 文件包含在 tag 中的方法。 有人请帮帮我。

最佳答案

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

您可以做的是在 pluginManagement 部分中创建一个包含所有全局插件配置的父 pom.xml。然后您可以在所有子 pom.xml 中使用 id“default-minify-1”激活配置的执行。但是配置只在父 pom.xml 中完成一次

参见 Reusing ant-snippets in multi-module maven build

关于xml - 在 pom.xml 中包含另一个 xml 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27774369/

相关文章:

xml - 水壶 'XML Output' 步骤改变/到/

java - jaxb2-maven-plugin 未生成 package-info.java

java - Weld 和测试 jar

java.lang.IllegalStateException - 提交响应后无法创建 session

java - 如何从 io.jsonwebtoken.Claims 转换为 java.util.Map<String,Object>?

Maven 版本被忽略了 includesList

xml - Scala:在文件中查找 DTD 声明

java - 如何在 Kotlin 中使用回调?

xml - 'xsl:copy-of' 和 'xsl:sequence' 有什么区别?

java - XMLStreamWriter 删除序言