exec-maven-plugin icon indicating copy to clipboard operation
exec-maven-plugin copied to clipboard

Using exec:exec with plugin dependencies and executableDependency

Open ShahinKordasti opened this issue 7 years ago • 8 comments

I want to execute a java class, but I want to run it async and hence why I am using exec:exec, but there does not seem to be a way to do that and at the same time use specific plugin dependencies (don't want project dependencies). This works fine with exec:java but not for exec:exec. The documentation says to omit executable when using executableDependency but then it just tries to run the jar directly (without java).

Is this something that is not supported or am I just not configuring it properly?

This is my configuration:

<plugin>
	<groupId>org.codehaus.mojo</groupId>
	<artifactId>exec-maven-plugin</artifactId>
	<version>1.6.0</version>
	<executions>
		<execution>
			<id>start-ipg</id>
			<phase>pre-integration-test</phase>
			<goals>
				<goal>exec</goal>
			</goals>
			<configuration>
				<includeProjectDependencies>false</includeProjectDependencies>
				<includePluginDependencies>true</includePluginDependencies>
				<executableDependency>
					<groupId>com.xxx.integration</groupId>
					<artifactId>test-dummy</artifactId>
				</executableDependency>
				<executable>java</executable>
				<arguments>
					<argument>com.xxx.integration.dummy.DummyStarter</argument>
					<argument>-startup</argument>
				</arguments>
				<async>true</async>
			</configuration>
		</execution>
	</executions>
	<dependencies>
		<dependency>
			<groupId>com.xxx.integration</groupId>
			<artifactId>test-dummy</artifactId>
			<version>0.0.1-SNAPSHOT</version>
		</dependency>
	</dependencies>
</plugin>

ShahinKordasti avatar Jun 14 '17 13:06 ShahinKordasti

I´ve got the same Problem. The jar-File i will exec runs System.exit(0). Because of this, maven will be exit because the are running in the same VM. Now I Try to run it with exec so they are in different VM´s.

Do you have any solutions?

dfoxg avatar Sep 01 '17 10:09 dfoxg

Have the exact same issues as @DanielFuchs98. Either this needs to be supported or exec:java forking should be supported.

samgurtman-zz avatar Dec 10 '17 11:12 samgurtman-zz

I too am having this very same problem. But I figured out a workaround.

The jar that you depend on will get downloaded into the maven repo. So, point to it explicitly.

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <dependencies>
        <dependency>
            <groupId>com.example</groupId>
            <artifactId>some-cli</artifactId>
            <version>${some=cli.version}</version>
        </dependency>
    </dependencies>
    <executions>
        <execution>
            <id>exec-stuff-and-junk</id>
            <goals>
                <goal>exec</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <executable>java</executable>
        <arguments>
            <argument>-classpath</argument>
            <argument>${settings.localRepository}/com/example/some-cli/${some-cli.version}/some-cli-${some-cli.version}.jar</argument>
            <argument>com.example.cli.MyAwesomeCLI</argument>
            <argument>stuff</argument>
            <argument>and</argument>
            <argument>junk</argument>
        </arguments>
    </configuration>
</plugin>

So much winning! This is still a bug though. Super annoying.

charlie-harvey avatar Mar 02 '18 19:03 charlie-harvey

@charlie-harvey Thanks, that worked.

bhagyas avatar May 08 '18 07:05 bhagyas

I had a similar problem that I solved with the </classpath> parameter. Take a look of my solution at Stack Overflow

pauloneves avatar Dec 04 '18 20:12 pauloneves

See https://stackoverflow.com/questions/44409624/maven-execjava-run-executable-plugin-dependency-jar-results-in-npe. It states that executableDependency is for native libraries. Using includePluginDependencies was sufficient in my case.

vkopichenko avatar Mar 14 '19 21:03 vkopichenko

The includePluginDependenciessuggestion will not work in case you need to use a different workingDirectory or async execution.

Therefore the executableDependency functionality should be extended to use java -jar in case the dependency is of the default type jar, while it should just use it as executable otherwise. The Jar file might have to include all its dependencies like as generated by the shade plugin. Alternatively the includePluginDependencies should also be supported for the <classpath> element, which might be easier (cleaner?) to be implement.

dranuhl avatar Sep 08 '20 10:09 dranuhl

I think that at least the exec goal should support the includePluginDependenciessuggestion and the dependencies must be included in de <classpath> element.

lujop avatar Jan 10 '22 15:01 lujop