Advanced Maven Failsafe Configurations plus AMPS

I’m trying to make AMPS run some integration tests that are a bit off their beaten path. While my tests compile just fine, the version of Surefire that comes bundled with AMPS cannot execute them.

I’ve debugged this to the point that I’m confident that what I need to do is register a custom provider, as described at Maven Failsafe Plugin – Selecting Providers .

The trouble is, I have no way to mess with the block for the version of the Surefire plugin that’s included in AMPS.

I’ve tried providing my own custom configuration for the maven failsafe plugin in my pom.xml file:

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>${maven.failsafe.version}</version>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.maven.surefire</groupId>
                        <artifactId>surefire-junit47</artifactId>
                        <version>${maven.failsafe.version}</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <id>integration-test</id>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                        <phase>integration-test</phase>
                    </execution>
                    <execution>
                        <id>verify</id>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <!-- The parent pom adds some standard dependencies, but these are the important ones -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.maven.surefire</groupId>
            <artifactId>surefire-junit47</artifactId>
            <version>${maven.failsafe.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

AMPS doesn’t run those tests during the integration-test phase because the JUnit47 provider isn’t available. However, I can run mvn failsafe:integration-test and the test executes just fine.

I either need to find a way to make my own custom integration-test execution run at the right time (after Confluence has started up, but before it has shut down) OR I need to figure out how to change the Surefire/Failsafe plugin config.

Notably, I have this problem for apps across Confluence, Bitbucket, and Jira.

@KamilaCzubaj - I heard a rumor you might know things about this, and that shamelessly @ing you on a public forum might be a way to get an answer. So, here I am. :slight_smile:

Hi @jcarter, thank you for reaching out,
I will talk to the team and let you know.

Kind regards,
Kamila Czubaj
Senior Product Manager on the Server Platform

1 Like

Hi Jonny, thanks for your question.

AMPS is meant to respect any configuration that you provide in the build/plugins section of your POM.

To help us investigate this, could you please provide a minimal project that demonstrates the problem?

Andrew

1 Like

@aswan - Thanks! Apologies for the delayed response.

So, I can provide an example, though it may require you to stretch the boundaries of the word “minimal”. :slight_smile:

Environment setup:

  1. Clone https://bitbucket.org/Adaptavist/scriptrunner-parent-pom/src/master/
  2. Checkout the branch bugfix/SRPLAT-1277-scriptrunner-samples-is-failing-to-run-tests
  3. Run mvn install
  4. Clone https://bitbucket.org/Adaptavist/scriptrunner-samples/
  5. Checkout the branch bugfix/SRPLAT-1250-experiment-with-goals-and-executions
  6. cd into the confluence subproject
  7. Run mvn clean verify to reproduce the problem. You should see that Confluence starts and stops, but does not run the tests.

For something to compare to, you can run mvn confluence:debug to start Confluence, then invoke Failsafe directly to see a working test run using mvn failsafe:integration-test -Dbaseurl="http://localhost:8080/confluence".

Hopefully that makes clear what the problem is.

I don’t seem to have access to that repo, Jonny.

I was able to clone scriptrunner-samples, though.

@aswan - my bad. You should be able to clone it now.

1 Like

Sorry to bother you again Jonny, but I get this when running mvn install on that branch of the scriptrunner-parent-pom project:

[ ERROR ] Failed to execute goal on project scriptrunner-bamboo-standard: Could not resolve dependencies for project com.adaptavist.pom:scriptrunner-bamboo-standard:pom:32-SNAPSHOT: Could not find artifact com.onresolve.bamboo.groovy:groovyrunner:jar:5.4.19 in maven-atlassian-com (https://packages.atlassian.com/maven/repository/internal) -> [Help 1]

Hey, I’m bothering you, remember? :slight_smile: Apologies for the time delays here, it’s been a week. :sweat:

That’s odd. The scriptrunner-parent-poms repo should have been able to resolve that dependency from https://nexus.adaptavist.com/content/repositories/external/com/onresolve/bamboo/groovy/groovyrunner/5.4.19/.

It should have had a repo setup for our public maven repo, based on the repository configuration in the base pom:

    <repositories>
        <!-- This is required to find the parent pom and ScriptRunner dependencies -->
        <repository>
            <id>adaptavist-external</id>
            <url>https://nexus.adaptavist.com/content/repositories/external</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <releases>
                <enabled>true</enabled>
                <checksumPolicy>fail</checksumPolicy>
            </releases>
        </repository>
    </repositories>

The best that I can figure is that there’s something in our poms that presumes our own internally presumed development environment setup (which does include adding our Nexus repo to your maven profile config).

However, even if I move my maven config files (~/.m2/settings.xml and ~/.m2/settings-security.xml) and do a mvn clean install, I’m able to download those dependencies and build the project.

I’m afraid I’m a bit like an ape with sticks when it comes to Maven, so this is probably some known issue that you will instantly recognize & school me. :slight_smile:

Is there anything in your maven config that might prevent it from honoring the repositories in the base pom? Or can you tweak it to look at the above nexus repositories?

So, @aswan, just to say a bit more, I suspect that the fundamental cause of the problem is that while AMPS does merge the <configuration> block of a build plugin, it doesn’t merge the <dependencies> block within the plugin’s configuration, which is what I actually need. I’m basing that judgment off of the code here:
https://bitbucket.org/atlassian/amps/src/f0d33e3de17ef36f36cf6e25b546af066347219c/amps-maven-plugin/src/main/java/com/atlassian/maven/plugins/amps/MavenGoals.java#lines-1242

That calls to org.twdata.maven.mojoexecutor.MojoExecutor#configuration, which seems to only get the configuration block.

Again, the configuration that isn’t being honored looks like this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>${maven.surefire.version}</version>
    <dependencies>
        <dependency>
            <groupId>org.apache.maven.surefire</groupId>
            <artifactId>surefire-junit47</artifactId>
            <version>${maven.surefire.version}</version>
        </dependency>
    </dependencies>
</plugin>

I need that dependency to direct surefire/failsafe to use junit47, but I’m pretty sure AMPS doesn’t copy it.

Notice that there is no configuration block in there, because I don’t need anything but the defaults.

See also, the bug report I’ve opened at https://ecosystem.atlassian.net/browse/AMPS-1553.

1 Like

[quote=“jcarter, post:10, topic:42302”]
I suspect that the fundamental cause of the problem is that while AMPS does merge the <configuration> block of a build plugin, it doesn’t merge the <dependencies> block within the plugin’s configuration[/quote]

Yes, this indeed seems to be the cause of your problem. I’ll take a look at the AMPS ticket you logged. Let’s continue the discussion there.

1 Like

Hey @jcarter @aswan,

are there any updates regarding this issue as I’m actually facing the exactly same problems.
I guess the discussion was continued here: [AMPS-1553] AMPS ignores failsafe plugin dependencies - Ecosystem Jira.

1 Like

I no longer work on AMPS, but I’ve asked the current maintainers to take a look at this thread.

Hey, @ArberBushati. I’ve more or less moved on to other things since all this and gave up on trying to make AMPS work for my use case in the short term. If the AMPS team comes back with some insights, though, I might be compelled to take a look.