<pluginmanagement>标记导致Maven2上的“找不到符号”</pluginmanagement>

时间:2014-01-28 00:07:51

标签: java eclipse maven symbols

我有一个pom.xml文件,其结构如下:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>someParentGroupId</groupId>
        <artifactId>someParentArtifactId</artifactId>
        <version>someParentVersionId</version>
    </parent>
    <artifactId>...</artifactId>
    <name>...</name>
    <packaging>war</packaging>
    <properties>
        <aspectj.version>1.6.12</aspectj.version>
        <roo.version>1.2.2.RELEASE</roo.version>
        <spring.version>3.1.0.RELEASE</spring.version>
        <camel.version>2.10-SNAPSHOT</camel.version>
        <spring-security.version>3.1.0.RELEASE</spring-security.version>
    </properties>

    <repositories>
        <repository>
            <id>someRepoId</id>
            <name>someRepoName</name>
            <url>someRepoURL</url>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>somePluginRepoId</id>
            <name>somePluginRepoName</name>
            <url>somePluginRepoURL</url>
        </pluginRepository>
    </pluginRepositories>

    <dependencies>
        <dependency>
            <groupId>someDependencyGroupId</groupId>
            <artifactId>someDependencyArtifactId</artifactId>
            <version>someDependencyVersion</version>
            <scope>someDependencyScope</scope>
        </dependency>
    </dependencies>
    <build>

    <!-- <pluginManagement> -->
        <plugins>
            <plugin>
                <groupId>somePluginGroupId</groupId>
                <artifactId>somePluginArtifactId</artifactId>
                <version>somePluginVersionId</version>
            </plugin>

        </plugins>
    <!-- </pluginManagement> -->
    </build>
</project>

当我对标签进行评论时,我可以毫无问题地运行mvn install,但Eclipse会在我的pom.xml中出现错误的椰子!

Plugin execution not covered by lifecycle configuration: org.codehaus.mojo:aspectj-maven-plugin:1.2:compile (execution: default, phase: process-sources)

Plugin execution not covered by lifecycle configuration: org.codehaus.mojo:aspectj-maven-plugin:1.2:test-compile (execution: default, phase: process-test-sources)

但是,如果我添加标签,我的任何Eclipse项目都没有错误,但我无法运行mvn install!以下是运行mvn -e install

的输出的一部分
/home/pedro/dss-project/dss/dss-server/src/main/java/net/jnd/thesis/domain/SessionCondition.java:[79,9] cannot find symbol
symbol  : method getValue()
location: class net.jnd.thesis.domain.SessionCondition
/home/pedro/dss-project/dss/dss-server/src/main/java/net/jnd/thesis/web/AdminController.java:[61,5] cannot find symbol
symbol  : method setValueRaw(java.lang.String)
location: class net.jnd.thesis.domain.Event
[INFO] Trace
org.apache.maven.BuildFailureException: Compilation failure
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:715)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
    at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:622)
    at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
    at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
    at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
    at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.CompilationFailureException: Compilation failure
    at org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:656)
    at org.apache.maven.plugin.CompilerMojo.execute(CompilerMojo.java:128)
    at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
    ... 17 more

我该如何解决这个问题?

可以在此处看到整个 pom.xml 文件:

1 个答案:

答案 0 :(得分:1)

如果你使用pluginManagement,你主要为列出的插件设置/配置东西,除了默认绑定到某个阶段的插件(例如maven-compiler-plugin)之外,不要执行它们。

父pom中的pluginManagement通常用于为所有孩子设置插件......

所以似乎(至少)你的一个插件(aspectj-maven-plugin?)需要在pluginManagement-tag之外的build-plugins-section中列出才能实现它的目标。

试试这样:

<build>
 <pluginManagement>
   <plugins>
    ...
    <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>aspectj-maven-plugin</artifactId>
            <version>1.2</version>
            <!-- NB: do not use 1.3 or 1.3.x due to MASPECTJ-90 and do not use 1.4
                due to declare parents issue -->
            <dependencies>
                <!-- NB: You must use Maven 2.0.9 or above or these are ignored (see
                    MNG-2972) -->
                <dependency>
                    <groupId>org.aspectj</groupId>
                    <artifactId>aspectjrt</artifactId>
                    <version>${aspectj.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.aspectj</groupId>
                    <artifactId>aspectjtools</artifactId>
                    <version>${aspectj.version}</version>
                </dependency>
            </dependencies>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                        <goal>test-compile</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <outxml>true</outxml>
                <aspectLibraries>
                    <aspectLibrary>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-aspects</artifactId>
                    </aspectLibrary>
                </aspectLibraries>
                <source>${java.version}</source>
                <target>${java.version}</target>
            </configuration>
    </plugin>
  </plugins>
 </pluginManagement>

 <plugins>
  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
  </plugin>
 </plugins>
 ...
</build>

修改 另外你必须告诉eclipse m2e插件有一些目标(编译/测试编译)与它的默认配置不匹配:

<build>
 <pluginManagement>
<plugins>
     ...
     <plugin>
    <groupId>org.eclipse.m2e</groupId>
    <artifactId>lifecycle-mapping</artifactId>
    <version>1.0.0</version>
    <configuration>
        <lifecycleMappingMetadata>
            <pluginExecutions>
                <pluginExecution>
                    <pluginExecutionFilter>
                        <groupId>org.codehaus.mojo</groupId>
                         <artifactId>aspectj-maven-plugin</artifactId>
                        <versionRange>[1.2,)</versionRange>
                <goals>
                    <goal>compile</goal>
                    <goal>test-compile</goal>
                </goals>
         </pluginExecutionFilter>
    <action>
        <execute />
    </action>
      </pluginExecution>
         </pluginExecutions>
    </lifecycleMappingMetadata>
  </configuration>
 </plugin>
</plugins>
</pluginManagement>
...