Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I disable the maven-compiler-plugin?

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.
like image 669
Andrew Eisenberg Avatar asked Jan 30 '13 21:01

Andrew Eisenberg


People also ask

Is Maven compiler plugin necessary?

Maven Compiler Plugin might be the most important plugin in Maven. It is used to compile the sources of your project, which transform Java files ( *. java ) into class files ( *.

How do I change my default Maven compiler?

Show activity on this post. Create a pom-only ( <packaging>pom</packaging> ) project that has the compiler settings (and any other default settings) you want. You give treat it like any other project (release it; deploy it to your Maven repo, etc.). It doesn't help much if all you want to set is compiler settings.

Is Maven compiler plugin required with spring boot?

Technically we can use both spring-boot-maven-plugin and maven-compiler-plugin in combination if the requirement is to create an executable jar as well as make sure source and target code have a specific version (which is accomplished by including maven-compiler-plugin).


4 Answers

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>
like image 82
Jintian DENG Avatar answered Oct 20 '22 05:10

Jintian DENG


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.

like image 35
Simon Kissane Avatar answered Oct 20 '22 03:10

Simon Kissane


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
like image 4
Vsevolod Golovanov Avatar answered Oct 20 '22 04:10

Vsevolod Golovanov


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

like image 2
gerrytan Avatar answered Oct 20 '22 03:10

gerrytan