How do I disable the maven-compiler-plugin?

╄→гoц情女王★ 提交于 2019-11-30 07:47:52

问题


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.

回答1:


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>



回答2:


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.




回答3:


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




回答4:


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


来源:https://stackoverflow.com/questions/14614446/how-do-i-disable-the-maven-compiler-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!