0

I am creating a non-java Maven artifact. In the pom.xml I resolve some dependencies and then run a custom script using exec plugin. Some files are created in a directory, but Maven does not see them when packaging them in a jar.

When I run mvn package twice, the second run does include the resource files in the jar.

Any ideas why this is happening? The script is run during the compile phase, so the files are already created when the package phase is creating the jar.


This is the relevant (hopefully) part of my pom.xml configuration:

<plugins>
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.4.0</version>
        <executions>
            <execution>
                <id>build-plugin</id>
                <phase>compile</phase>
                <goals>
                    <goal>exec</goal>
                </goals>
                <configuration>
                    <executable>bash</executable>
                    <arguments>
                        <argument>build_plugin.sh</argument>
                        <argument>${workspace}</argument>
                        <argument>${plugin}</argument>
                    </arguments>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>

<resources>
    <resource>
        <directory>${project.basedir}/${outputPath}</directory>
        <includes>
            <include>**</include>
        </includes>
        <excludes>
            <exclude>target/**</exclude>
        </excludes>
    </resource>
</resources>

All the variables and paths are valid, on the second run I am getting a jar with expected content. But not during the first.

FINDarkside
  • 2,102
  • 1
  • 18
  • 26
Martin Melka
  • 7,177
  • 16
  • 79
  • 138

1 Answers1

1

in maven Default Lifecycle the processing of resources happens before compiling see https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference

What you have to do is changing the build phase of the "exec-maven-plugin", use "generate-sources" instead of "compile"

<plugins>
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.4.0</version>
        <executions>
            <execution>
                <id>build-plugin</id>
                <phase>generate-sources</phase>
                <goals>
                    <goal>exec</goal>
                </goals>
                <configuration>
                    <executable>bash</executable>
                    <arguments>
                        <argument>build_plugin.sh</argument>
                        <argument>${workspace}</argument>
                        <argument>${plugin}</argument>
                    </arguments>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>

<resources>
    <resource>
        <directory>${project.basedir}/${outputPath}</directory>
        <includes>
            <include>**</include>
        </includes>
        <excludes>
            <exclude>target/**</exclude>
        </excludes>
    </resource>
</resources>
FINDarkside
  • 2,102
  • 1
  • 18
  • 26
Hisham Khalil
  • 1,054
  • 8
  • 9