gpt4 book ai didi

java - 标签在 Maven2 上导致 "cannot find symbol"

转载 作者:行者123 更新时间:2023-12-01 13:34:11 26 4
gpt4 key购买 nike

我有一个具有以下结构的 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文件可以在这里看到:

最佳答案

如果您使用pluginManagement,您主要对列出的插件进行设置/配置,而不一定执行它们,除了默认绑定(bind)到阶段的插件(例如maven-compiler-plugin)。

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

所以看来(至少)您的插件之一(aspectj-maven-plugin?)需要在pluginManagement标签之外的build-plugins-部分中列出才能执行其目标。

尝试这样:

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

关于java - <pluginManagement> 标签在 Maven2 上导致 "cannot find symbol",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21394421/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com