tag causes “cannot find symbol”

2019-06-09 08:18发布

I have a pom.xml file that has the following structure:

<?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>

When I have the tag commented, I can run mvn install without problems, but Eclipse goes coconuts with errors in my 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)

If however, I add the tag I have no errors in any of my Eclipse projects, but I cannot run mvn install ! Here is part of the output from running 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

How can I fix this?

The entire pom.xml file can be seen here:

1条回答
干净又极端
2楼-- · 2019-06-09 08:53

If you use pluginManagement, you mainly do setting/config stuff for the listed plugins and not execute them necessarily except for plugins that bind to a phase by default (like the maven-compiler-plugin e.g.).

The pluginManagement in a parent pom is often used to set up the plugins for all children ...

So it seems that (at least) one of your plugins (aspectj-maven-plugin?) needs to be listed in the build-plugins-section outside the pluginManagement-tag to get it's goals executed.

Try sth like this:

<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>

EDIT Additionally you have to tell the eclipse m2e plugin that there are some goals (compile/test-compile) that don't match it's default configuration:

<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>
...
查看更多
登录 后发表回答