2012-07-20 122 views
1

我使用SpringSource Tool Suite(STS)和Maven + m2eclipse。在我最近的項目中,我面臨着一個問題,即將現有的Maven項目從SVN正確導入STS。當我使用import -> Maven -> 'existing Maven project',該項目將導入反而會產生以下問題:爲什麼STS/m2eclipse不能跟蹤我的Maven依賴關係?

  • src/main/javasrc/test/java沒有拿起作爲源文件夾。 STS將配置src作爲源文件夾,並將main/test添加到軟件包名稱中。
  • Maven依賴項庫不會添加到java構建路徑。

我可以手動糾正源文件夾,但是當我嘗試添加「的Maven管理依賴」庫構建路徑我得到的消息,「使用Maven項目設置配置Maven依賴分辨率」和庫未添加。我似乎可以設置的唯一Maven項目設置是活動配置文件和「解決工作區項目的依賴關係」(選中),這兩者似乎都沒有什麼區別。

Add Maven Managed Dependencies Maven Project Settings

如果我在命令行中運行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.xmlsrc文件夾。
  • 我使用外部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> 

有沒有人對如何任何想法:

  1. 得到m2eclipse的進口才能正常工作?或
  2. 配置STS允許我在項目創建/轉換後將maven託管依賴添加到構建路徑?

回答

1

以下部分:

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

+0

項目中有一些常規代碼,但主要是Java。我們正在使用groovy-eclipse編譯器。 – Marquee 2012-07-24 17:21:19

+0

我希望在你的pom的構建插件部分看到這一點,但我沒有看到任何其他編譯器的參考。 (這不在你原來的問題範圍內,所以也許並不重要。) – 2012-07-24 18:50:54

+0

最後有機會今天測試一下,你完全正確。從pom中移除該部分可以根據需要導入所有內容。謝謝!! – Marquee 2012-07-25 17:58:50

0

我已經有過這個問題了幾次,每次解決方案都是在安德魯答案的精神:maven接受但是m2eclipse barfs上的某些部分。

因此,我建議刪除部分的pom 1,直到您可以成功地實現項目。在每個pom編輯之後繼續運行maven -> update configuration,直到它按照它應該的方式工作。我通常先從最可疑的(即最複雜的)開始,一次刪除一個插件配置標記塊。

一旦它發生變化,你可以恢復POM,它應該仍然按預期工作。

當我運行後,我會研究有問題的配置以試圖找出'正確的'修正(依據m2eclipse,無論如何)。

我發佈在我的問題中的解決方法將暫時工作,並且我從未發現任何負面影響,但此解決方案感覺不太好,並且會幫助您永久隔離和解決問題。