2

Let's say that my standard configration in Maven is:

  • compile, test and package - do their normal thing
  • pre-integration-test:
    • Generate DB schema scripts (maven-antrun-plugin with concat)
    • Run those scripts on DB (sql-maven-plugin)
    • Run a custom Java program to populate DB with data (exec or antrun)
    • Start server from jar (maven-antrun-plugin, because exec wouldn't fork)
  • integration-test: run tests using the server running from jar
  • post-integration-test: stop the server (exec)

With normal execution path it works just fine (modulo bugs in Maven plugin ordering, besides the point).

Now, I would like to have a single command to only generate and execute the DB schema scripts, and another command to only run the Java program to populate database.

So far I figured I could put install-schema, populate-db and start-jetty in their own profiles, then:

mvn pre-integration-test -Pinstall-schema

This is bad, because it still would run all the preceding phases, and I really don't want to compile, test and package for it.

Is it possible to somehow run those "things" (several plugin executions, a profile) in isolation, ignoring the lifecycle or skipping compile-test-package?

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Konrad Garus
  • 53,145
  • 43
  • 157
  • 230

1 Answers1

0

Yes, I think you can do that with conditional activation through certain properties for the Maven profiles, e.g.:

<profile>
    <id>install-schema</id>
    <activation>
        <property>doItPlz</property>
    </activation>
</profile>
...

This way the profile is activated only if that given doItPlz property is present -- so you can create one for the build, the db initialization, etc.

The command you have to use is then modified to:

mvn -DdoItPlz ...

Hope that helps something.

rlegendi
  • 10,466
  • 3
  • 38
  • 50
  • The question is not so much "how to run a profile on condition", as it is "how to run *only* this one profile, ignoring the lifecycle completely, skipping compile, test, package and whatever else I do not need". – Konrad Garus Dec 03 '13 at 13:15
  • I don't know how many profiles do you have, but wouldn't it solve your issue if you would assign a property for each of them? That way you could specify which profiles to run. – rlegendi Dec 03 '13 at 16:51