Maven依赖插件(解包依赖)会忽略配置

时间:2018-11-30 11:55:47

标签: maven maven-dependency-plugin

发生以下问题: 项目中有一个依赖项。依赖项包含.js和.css文件(本质上它们将用作资源)。我需要提取这些文件并将其放在特定位置。我曾想为此使用maven-dependency-plugin,但它不使用我指定的配置(使用默认值)。请告诉我哪里错了。

pom.xml:

<dependencies>
    <dependency>
        <groupId>my.group.Id</groupId>
        <artifactId>my-artifact-id</artifactId>
        <version>my_version</version>
    </dependency>
</dependencies>

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.10</version>
                <executions>
                    <execution>
                        <id>unpack</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>unpack-dependencies</goal>
                        </goals>
                        <configuration>
                            <includeScope>runtime</includeScope>
                            <includeGroupIds>my.group.Id</includeGroupIds>
                            <includeArtifactIds>my-artifact-id</includeArtifactIds>
                            <includes>**/*.js,**/*.css</includes>
                            <outputDirectory>${project.basedir}/my/path</outputDirectory>
                            <overwriteReleases>true</overwriteReleases>
                            <overwriteSnapshots>true</overwriteSnapshots>
                            <overwriteIfNewer>true</overwrteIfNewer>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

1 个答案:

答案 0 :(得分:1)

您要在<pluginManagement>部分中声明您的插件执行。本节非常适合将配置放在一个地方并在以后重用,但不会执行您的插件。

尝试一下:

  <build>
      <pluginManagement>
          <plugins>
              <plugin>
                  <groupId>org.apache.maven.plugins</groupId> <!-- your example contained a typo. -->
                  <artifactId>maven-dependency-plugin</artifactId>
                  <version>2.10</version>
                  <executions>
                      <execution>
                          <id>unpack</id>
                          <phase>generate-resources</phase>
                          <goals>
                              <goal>unpack-dependencies</goal>
                          </goals>
                          <configuration>
                              <includeScope>runtime</includeScope>
                              <includeGroupIds>commons-lang</includeGroupIds>
                              <includeArtifactIds>commons-lang</includeArtifactIds>
                              <includes>**/*.js,**/*.css</includes>
                              <outputDirectory>${project.basedir}/my/path</outputDirectory>
                              <overwriteReleases>true</overwriteReleases>
                              <overwriteSnapshots>true</overwriteSnapshots>
                              <overwriteIfNewer>true</overwriteIfNewer> <!-- Typo in your POM here as well -->
                          </configuration>
                      </execution>
                  </executions>
              </plugin>
          </plugins>
      </pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-dependency-plugin</artifactId>
        </plugin>
      </plugins>
   </build>
相关问题