1

This question does an excellent job of explaining how to skip a Maven profile based upon the Properties sent to Maven, conditionally execute maven plugins which would be great, but I'm in a situation where I have two Profiles that execute one after the other, however if one of the Java methods within the first Profile gets into a specific state, I do not want to run the second Profile at all.

I have several very good reasons for wanting to run this entire process from a single Maven command.

Is this possible?

I'm imagining something like this, but don't really know how to reference the property from Java.

From pom.xml:

<profile>
        <id>Profile 2</id>
            <activation>
                <property><name>!maven.test.skip</name></property>
                <property><name>!skipTests</name></property>
            </activation>
            <build>
                ...
            </build>
</profile>

From some Java Class:

public static void main(String... args) {
  if(weShouldRunProfile2){
    skipTests = false; //obviously wrong, but not sure what to put here if this is even possible
  }
}
Glen Pierce
  • 4,401
  • 5
  • 31
  • 50

2 Answers2

0

It looks like I could call Maven again from within my Java process by following the instructions here: How to run maven from java?

A simple invocation API : maven-invoker.

Project documentation : http://maven.apache.org/shared/maven-invoker/

Usage : http://maven.apache.org/shared/maven-invoker/usage.html

InvocationRequest request = new DefaultInvocationRequest();
request.setPomFile( new File( "/path/to/pom.xml" ) );
request.setGoals( Arrays.asList( "clean", "install" ) );

Invoker invoker = new DefaultInvoker();
invoker.execute( request );
Community
  • 1
  • 1
Glen Pierce
  • 4,401
  • 5
  • 31
  • 50
0

Ultimately, I decided to just use the file system to solve this. Profile 1 writes a file that contains data on what Profile 2 should do, then Profile 2 reads that file and exits early if that file indicates that it should do so.

Glen Pierce
  • 4,401
  • 5
  • 31
  • 50