为什么STS/m2eclipse不能跟踪我的Maven依赖关系?
我使用SpringSource Tool Suite(STS)和Maven + m2eclipse。在我最近的项目中,我面临着一个问题,即将现有的Maven项目从SVN正确导入STS。当我使用import -> Maven -> 'existing Maven project'
,该项目将导入反而会产生以下问题:为什么STS/m2eclipse不能跟踪我的Maven依赖关系?
- 的
src/main/java
和src/test/java
没有拿起作为源文件夹。 STS将配置src
作为源文件夹,并将main/test添加到软件包名称中。 - Maven依赖项库不会添加到java构建路径。
我可以手动纠正源文件夹,但是当我尝试添加“的Maven管理依赖”库构建路径我得到的消息,“使用Maven项目设置配置Maven依赖分辨率”和库未添加。我似乎可以设置的唯一Maven项目设置是活动配置文件和“解决工作区项目的依赖关系”(选中),这两者似乎都没有什么区别。
如果我在命令行中运行mvn install
成功生成该项目。如果我运行mvn eclipse:eclipse
然后导入到STS中,那么一切都按预期工作,但是当然,每次更新pom时都必须重新运行它,这是不可取的。
我工作围绕它运行mvn eclipse:eclipse
,然后手动更新的.classpath以消除eclipse:eclipse
加入M2_REPO
依赖关系,并添加m2eclipse的依赖项:
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
然后我导入现有Maven项目和它的工作如预期。但是,这是一个黑客攻击,我不确定在使用m2eclipse时运行eclipse:ecplise
会产生什么后果。
我已经在其他maven项目上工作过,并且没有正确导入它们的问题。
可能相关的信息:
- 这是一个Web应用程序项目。
- 颠覆回购仅包含
pom.xml
和src
文件夹。 - 我使用外部maven安装,它是3.0版本。3
- 我们使用一个现场Artifactory的回购为神器下载
事情我已经尝试:
- 下载从SVN到本地磁盘,然后导入到使用进口STS现有Maven项目
- 导入项目从SVN进入STS,配置 - >启用Maven自然
- 运行
mvn eclipse:eclipse
然后导入(工作但需要手动修改m2e的类路径) - 搜索stackoverflow,找到this question这是非常相似,但答案似乎并没有解决我的问题。
的pom.xml:
<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>
<groupId>com.company.group</groupId>
<artifactId>artifact</artifactId>
<version>1.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>My Project</name>
<description>My Project</description>
<properties>
<java-version>1.6</java-version>
<org.springframework-version>3.1.0.RELEASE</org.springframework-version>
<!-- Lots of other versions omitted -->
</properties>
<repositories>
<repository>
<id>repoId</id>
<name>repoName</name>
<url>http://fake.company.com/artifactory/repo</url>
<layout>default</layout>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>repoId</id>
<name>repoName</name>
<url>http://fake.company.com/artifactory/repo</url>
</pluginRepository>
</pluginRepositories>
<!-- Configurations required for deploy plugin. Artifacts are deployed to
artifactory -->
<distributionManagement>
<repository>
<id>repoId</id>
<name>repoName-releases</name>
<url>http://fake.company.com/artifactory/apps-releases-local</url>
</repository>
<snapshotRepository>
<id>repoId</id>
<name>repoName-snapshots</name>
<url>http://fake.company.com/artifactory/apps-snapshots-local</url>
</snapshotRepository>
</distributionManagement>
<scm>
<connection>scm:svn:https://fake.company.com/svn/fake-repo/trunk</connection>
<developerConnection>scm:svn:https://fake.company.com/svn/fake-repo/trunk</developerConnection>
<url>https://fake.company.com/svn/fake-repo/trunk</url>
</scm>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- Lots of other dependencies omitted -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/TestUtil.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<verbose>true</verbose>
<source>${java-version}</source>
<target>${java-version}</target>
<compilerVersion>${java-version}</compilerVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warName>war-name</warName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>install</id>
<phase>install</phase>
<goals>
<goal>sources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<formats>
<format>html</format>
</formats>
<instrumentation>
<ignores>
<ignore>path/**/*Test.class</ignore>
</ignores>
<excludes>
<exclude>path/Constants.class</exclude>
<exclude>path/*.class</exclude>
</excludes>
</instrumentation>
<check>
<haltOnFailure>false</haltOnFailure>
<totalBranchRate>25</totalBranchRate>
<totalLineRate>41</totalLineRate>
<packageLineRate>25</packageLineRate>
<packageBranchRate>15</packageBranchRate>
</check>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>cobertura</goal>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${org.apache.cxf-version}</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/wsdl/automation.wsdl</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated/cxf</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<additionalProjectnatures>
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
<projectnature>org.eclipse.jdt.groovy.core.groovyNature</projectnature>
</additionalProjectnatures>
<additionalBuildcommands>
<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
</additionalBuildcommands>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings
only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.cxf</groupId>
<artifactId>
cxf-codegen-plugin
</artifactId>
<versionRange>
[${org.apache.cxf-version},)
</versionRange>
<goals>
<goal>wsdl2java</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<versionRange>[2.3.2,)</versionRange>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<profiles>
<!-- Deployment profiles omitted -->
</profiles>
</project>
有没有人对如何任何想法:
- 得到m2eclipse的进口才能正常工作?或
- 配置STS允许我在项目创建/转换后将maven托管依赖添加到构建路径?
以下部分:
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<versionRange>[2.3.2,)</versionRange>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
在你的构建禁用Java编译器的不幸后果。删除它,我会想象的事情工作。
我也看到了这一点:
<projectnature>org.eclipse.jdt.groovy.core.groovyNature</projectnature>
这是一个常规项目?如果是的话你使用gmaven或者groovy-eclipse-compiler?
我已经有过这个问题了几次,每次解决方案都是在安德鲁答案的精神:maven接受但是m2eclipse barfs上的某些部分。
因此,我建议删除部分的pom 1,直到您可以成功地实现项目。在每个pom编辑之后继续运行maven -> update configuration
,直到它按照它应该的方式工作。我通常先从最可疑的(即最复杂的)开始,一次删除一个插件配置标记块。
一旦它发生变化,你可以恢复POM,它应该仍然按预期工作。
当我运行后,我会研究有问题的配置以试图找出'正确的'修正(依据m2eclipse,无论如何)。
我发布在我的问题中的解决方法将暂时工作,并且我从未发现任何负面影响,但此解决方案感觉不太好,并且会帮助您永久隔离和解决问题。
项目中有一些常规代码,但主要是Java。我们正在使用groovy-eclipse编译器。 – Marquee 2012-07-24 17:21:19
我希望在你的pom的构建插件部分看到这一点,但我没有看到任何其他编译器的参考。 (这不在你原来的问题范围内,所以也许并不重要。) – 2012-07-24 18:50:54
最后有机会今天测试一下,你完全正确。从pom中移除该部分可以根据需要导入所有内容。谢谢!! – Marquee 2012-07-25 17:58:50