chrisdchristo / capsule-maven-plugin

Capsule Maven Plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Maven dependencies with type "test-jar" are not correctly resolved to the test jar file.

cgordon opened this issue · comments

We have a project in which we run integration tests locally (using failsafe) and also remotely (as smoke tests). That requires us to package our test code into a jar file, for which we currently use the Maven shade plugin. I would love to migrate from Maven shade to Capsule using this Maven plugin, but currently it does not support packaging test jars.

For Maven shade, all we had to do was add a dependency that looked like this:

<dependency>
  <groupId>some.group</groupId>
  <artifactId>some.artifact</artifactId>
  <type>test-jar</type>
</dependency>

Then, in the pom file for that artifact we just added this plugin:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>test-jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

That plugin creates an --test.jar file, which is then packaged by Maven Shade in the other project.

I took a look at the code for this plugin, and it looks like the Maven Aether libraries do not support the tag for dependencies. If that is the case, this may be a difficult thing to fix. I'm sending this issue in the hopes that there is a work-around about which I am not aware.

The code you've added to include arbitrary dependencies looks like it could easily be modified to include test jars, as that code doesn't use Aether, and the API it uses does know about the type tag. If there isn't a known workaround for Aether, I can send a pull request to use the dependency mechanism instead, which is good enough for us.

Thank you!

Hi, please check the latest 1.2.0 release. I added support for embedding test scoped jars (as well as provided scoped jars).

See this for some information on scope.

Essentially you want to include your test jars with the flag <includeTestDep>true</includedTestDep>, so something like so:

<plugin>
    <groupId>com.github.chrischristo</groupId>
    <artifactId>capsule-maven-plugin</artifactId>
    <version>${capsule.maven.plugin.version}</version>
    <executions>
        <execution>
            <goals>
                <goal>build</goal>
            </goals>
            <configuration>
                <appClass>hello.HelloWorld</appClass>
                <includeApp>true</includeApp>
                <includeCompileDep>true</includeCompileDep>
                <includeRuntimeDep>true</includeRuntimeDep>
                <includeTestDep>true</includeTestDep>
                <includeTransitiveDep>true</includeTransitiveDep>
            </configuration>
        </execution>
    </executions>
</plugin>

Let me know if you need any more help :).

Fantastic, thanks for this!

The release has been uploaded to maven central, just wait it a bit for the update to propagate.