Alexandros
Alexandros

Reputation: 2249

Maven plugin conditional execution based on a previous plugin's execution (maven-compiler-plugin)

Is it possible to conditionally execute a goal in compile phase, based on whether the maven-compiler-plugin actually detected source changes and therefore compiled and produced new class files?

My use case would be to do things like run findbugs or jacoco plugins only when there's new byte code in the project.

Currently, I unconditionally run findbugs by hooking it into the compile phase:

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>findbugs-maven-plugin</artifactId>
        <executions>
            <execution>
                <id>findbugs-check-compile</id>
                <phase>compile</phase>
                <goals>
                    <goal>check</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

However, if I repeatedly execute "mvn package" I get:

[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ my-prj ---
[INFO] Nothing to compile - all classes are up to date
[INFO] >>> findbugs-maven-plugin:3.0.1:check (findbugs-check-compile) > :findbugs @ my-prj >>>
[INFO] --- findbugs-maven-plugin:3.0.1:findbugs (findbugs) @ my-prj ---
[INFO] Fork Value is true
[INFO] Done FindBugs Analysis....

Notice how maven-compiler-plugin detects "Nothing to compile - all classes are up to date". I'd like to only execute findbugs:check afterwards if this is NOT the case (or equivalently, I'd like to SKIP the "findbugs:check" goal execution if this indeed IS the case and nothing has changed).

NOTE 1: I know about profiles and conditional activation based on things like OS / architecture / system properties / etc, but my understanding is that these are evaluated early when maven starts, and cannot change later during the build.

NOTE 2: I've also seen maven-ant-plugin mentioned, but I'd like to just skip the extra plugin's execution altogether. I don't want to add an antrun execution just to be able to skip findbugs.

NOTE 3: I need to be able to do this for multiple plugins, not just findbugs

Upvotes: 2

Views: 2480

Answers (1)

javapapo
javapapo

Reputation: 1342

to be honest I dont think there is a way to do this. Only the sort of workarounds but not exactly your exact need (based on profiles, property setting from profile1 to be picked up by another profile etc).

Something close to that is usually achieved with tools like jenkins, where you set a basic job e.g do a package (compile) if it succeeds or completes or you see something being generated, then you activate a post-build job to execute find bugs.

Upvotes: 1

Related Questions