1

We have a profile that uses maven-antrun-plugin to run a downloaded JAR.

Exhibit A: (this works)

We can reference the downloaded JAR using the property ${maven.dependency.com.foobar.target-jar.jar.path} (Can I use the path to a Maven dependency as a property?). But in this solution, the custom dependency and repository information isn't limited to just the scope of the profile.

<project>
    ...
    <repositories>
        <repository>
            <id>thirdparty</id>
            <name>Third Party</name>
             <url>
                 [URL for the repository that holds the target JAR]
             </url>
             <layout>default</layout>
        </repository>
    </repositories>
    ...
    <dependencies>
        <dependency>
            <groupId>com.foobar</groupId>
            <artifactId>target-jar</artifactId>
            <version>1.0.0</version>
        </dependency>
    </dependencies>
    ...
    <profiles>
        <profile>
            <id>runJARprofile</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.8</version>
                        <inherited>false</inherited>
                        <executions>
                            <execution>
                                <id>run-jar</id>
                                <phase>package</phase>
                                <configuration>
                                    <target name="runJar" fork="true">
                                        <java jar="${maven.dependency.com.foobar.target-jar.jar.path}" />
                                    </target>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
...
</project>

Exhibit B: (haven't gotten it working)

Here, we moved the dependency and repository information into the profile. Maven downloads the artifact successfully, but we no longer know how to reference it by property.

<project>
    ...

    <profiles>
        <profile>
            <pluginRepositories>
                <repository>
                    <id>thirdparty</id>
                    <name>Third Party</name>
                     <url>
                         [URL for the repository that holds the target JAR]
                     </url>
                     <layout>default</layout>
                </repository>
            </pluginRepositories>
            ...
            <id>runJARprofile</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.8</version>
                        <inherited>false</inherited>
                        <dependencies>
                            <dependency>
                                <groupId>com.foobar</groupId>
                                <artifactId>target-jar</artifactId>
                                <version>1.0.0</version>
                            </dependency>
                        </dependencies>
                        <executions>
                            <execution>
                                <id>run-jar</id>
                                <phase>package</phase>
                                <configuration>
                                    <target name="runJar" fork="true">
                                        <java jar="${?????}" />
                                    </target>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
...
</project>
Community
  • 1
  • 1
thn929
  • 21
  • 2
  • I'm not sure I understand the problem / question. Where is the property `maven.dependency.com.foobar.target-jar.jar.path` defined in the first place? – Tunaki Apr 25 '16 at 18:44
  • 1
    @Tunaki Looks like first example it pulled from the `pom`'s `` with the `${maven.dependency.com.foobar.target-jar.jar.path}`, when the second example wants to use a `` that is added to the ``. I think the question is "how can you use a dependency from the plugin's dependency scope in the _maven-antrun-plugin_?". – mkobit Apr 25 '16 at 19:03
  • Based on [this link](http://maven.apache.org/plugins/maven-antrun-plugin/examples/classpaths.html), the property format `${maven.dependency.com.foobar.target-jar.jar.path}` is deprecated, so we should be using `${com.foobar:target-jar:jar}` instead. Tried this in Exhibit A and it works, but still not working in Exhibit B. – thn929 Apr 25 '16 at 19:27
  • Why is `Third Party` in **A** within `` and in **B** within ``? Are there still essential parts missing in your question's POM excerpts? – Gerold Broser Apr 25 '16 at 19:28
  • @GeroldBroser: the `` vs `` issue may need a question of its own. In short, for **Exhibit B**, if I replace `` with ``, Maven is unable to locate and download `com.foobar.target-jar`. – thn929 Apr 25 '16 at 19:36

1 Answers1

1

I crated a POM similar to your Exhibit B here and got the following message during a mvn package -P runJARprofile:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.8:run
(run-jar) on project so-36848518: An Ant BuildException has occured:
Cannot execute a jar in non-forked mode. Please set fork='true'.
[ERROR] around Ant part ...<java jar="${my:test:jar}"/>...

I changed the respective line to:

<java jar="${my:test:jar} fork="true"/>

and:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
  • Yes, I have the `fork="true"` set in our real project. I was trying to declutter and generalize the examples... shouldn't have removed it without further understanding it. I'll update the original post. Thanks! – thn929 Apr 25 '16 at 22:00