簡體   English   中英

Maven依賴插件-使用依賴解壓縮時如何確保工件存在

[英]Maven dependency plugin - How can I ensure that an artifact is present when using dependency-unpack

我想知道是否有一種方法可以在使用Maven依賴插件的dependency-unpack目標時強制解壓依賴關系。 我正在使用下面的配置,問題是,如果在pom的“ dependencies”部分中沒有為“ $ {properties.artifactId}”指定依賴項,即使沒有拆包,構建仍會繼續進行。 它總是會在測試階段稍后失敗,但是如果在不存在依賴項的情況下構建可能失敗,它將更加容易。 那么,有誰知道可以強制執行的方式嗎?

謝謝

碼頭

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
      <execution>
        <id>unpack-properties</id>
        <phase>generate-resources</phase>
        <goals>
          <goal>unpack-dependencies</goal>
        </goals>
        <configuration>
          <includeArtifactIds>${properties.artifactId}</includeArtifactIds>
          <outputDirectory>${project.build.directory}</outputDirectory>
          <includes>${properties.file.name}</includes>
        </configuration>
      </execution>
    </executions>
  </plugin>

可以執行幾個maven-enforcer-plugin 您需要在依賴插件之前運行一個,以確保$ {properties.artifactId}具有一個值,然后在依賴插件之后運行,以確保目標位置中有文件。 這是想法,根據您的要求進行修改。

如果可用的規則不太適合,您也可以編寫自己的規則。

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-enforcer-plugin</artifactId>
  <version>fillInTheVersion</version>
  <executions>
    <execution>
      <id>enforce-config-properties</id>
      <phase>validate</phase>
      <goals>
        <goal>enforce</goal>
      </goals>
      <configuration>
        <rules>
          <requireProperty>
            <property>properties.artifactId</property>
            <message><![CDATA[### Missing property 'properties.artifactId': the artifact that ....]]></message>
          </requireProperty>
        </rules>
      </configuration>
    </execution>
    <execution>
      <id>enforce-files-exist</id>
      <phase>process-resources</phase>
      <goals>
        <goal>enforce</goal>
      </goals>
      <configuration>
        <rules>
          <requireFilesExist>
            <files>
              <file>${project.build.directory}/${properties.artifactId}</file>
            </files>
            <message><![CDATA[### Did not find unpacked artifact ...]]></message>
          </requireFilesExist>
        </rules>
      </configuration>
    </execution>
  </executions>
</plugin>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM