30

I have a maven project that uses the aspectj-compiler-plugin. I use intertype declarations so there are references to Aspect code in my Java code. Because of this, the maven-compiler-plugin fails to compile since it does not compile the aspect code.

My question is: how do I disable the maven-compiler-plugin from running because it is not doing anything useful?

There are several ways that I can get this project compiling, but they are sub-optimal:

  1. Add exclusion filters to the maven-compiler-plugin. The plugin will still run, but it will not try to compile anything. Problem is that this breaks the ajdt project configurator in Eclipse
  2. Move all java code to the aspectj folders. This doesn't feel right either.
Andrew Eisenberg
  • 28,387
  • 9
  • 92
  • 148

4 Answers4

37

You can disable the a plugin by set the phase of the plugin to none.

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <executions>
                <execution>
                    <id>default-compile</id>
                    <phase>none</phase>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
allprog
  • 16,540
  • 9
  • 56
  • 97
Jintian DENG
  • 3,152
  • 20
  • 22
  • The solution worked flawlessly. I am running into a situation where I was getting this error: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:x.x.x.:compile (default-compile). The above solution takes care of that for now. – Kumar S Nov 21 '17 at 06:24
31

In Maven 3, the following will do this, for example disabling the clean plugin:

   <build>
      <plugins>
         <plugin>
            <artifactId>maven-clean-plugin</artifactId>
            <version>2.4.1</version>
            <executions>
               <execution>
                  <id>default-clean</id>
                  <phase>none</phase>
               </execution>
            </executions>
         </plugin>
      </plugins>
   </build>

The same technique can be used for any other plugin defined in the super-POM, the packaging type, or the parent POM. The key point is that you must copy the <id> shown by help:effective-pom, and change the <phase> to an invalid value (e.g. "none"). If you don't have the <id> (as e.g. in Jintian DENG's original answer – it has since been edited to add one), it will not work, as you have discovered.

Simon Kissane
  • 4,373
  • 3
  • 34
  • 59
7

Either configure the skipMain parameter:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <skipMain>true</skipMain>
            </configuration>
        </plugin>
    </plugins>
</build>

Or pass the maven.main.skip property:

mvn install -Dmaven.main.skip=true
Vsevolod Golovanov
  • 4,068
  • 3
  • 31
  • 65
  • 1
    It's funny, there are two solutions for this that talk about phase "none," yet this was the only solution that worked for me. Using phase none would still cause maven-compiler-plugin to try and build my Java 9 code as Java 6 even if I have other executions in the compile phase! – Alex Barker Aug 28 '20 at 23:29
2

The reason maven-compiler-plugin executes in the first place is because you trigger one of the default lifecycle bindings. For example if you're packaging jar using mvn package, it will trigger compile:compile at compile phase.

Maybe try not to use the default lifecycle, but use mvn aspectj:compile instead.

http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html has more information about maven default lifecycle bindings

gerrytan
  • 40,313
  • 9
  • 84
  • 99
  • 1
    This works if all projects are aspectj projects, but in my multi-project build, some are aspectj project and some are not. This will not work for me as it is, unless there is a way to mix lifecycles depebding on project. – Andrew Eisenberg Jan 31 '13 at 19:16