0

I'm wondering if there is a way to enforce the existence of a dependency to unpack when using the dependency-unpack goal of the maven dependency plugin. I'm using the configuration below and the problem is that if there is no dependency specified for "${properties.artifactId}" in the dependencies section of the pom the build goes ahead even though nothing has been unpacked. It invariably fails later at the test stage but it would be so much easier if the build could fail when no dependency is present. So does anyone know of a way that this can be enforced?

Thanks

Piers

<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>
PiersyP
  • 5,003
  • 2
  • 33
  • 35
  • Maybe using a dependency:resolve (http://maven.apache.org/plugins/maven-dependency-plugin/resolve-mojo.html) before can help you. But the dependency:unpack-dependencies itself cannot be configured to fail if nothing is found. – Tome Oct 16 '13 at 12:00
  • Thanks Tome, but maven dependency resolve is already being executed as part of the generate-sources phase before the unpack is being executed, but the problem is that if I haven't specified the dependency then dependency-unpack unpacks nothing! – PiersyP Oct 16 '13 at 13:43

1 Answers1

0

A couple of executions of the maven-enforcer-plugin should do it. You need one to run before the dependency plugin, to make sure ${properties.artifactId} has a value, then another that runs after the dependency plugin to make sure there are files in the target location. Here's the idea, modify for your requirements.

You may write your own rules too if those available don't quite fit.

<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>
user944849
  • 14,524
  • 2
  • 61
  • 83