2012-01-02 102 views
2

基於PlayN Getting Started wiki page,我在eclipse中創建了一個骨架項目(稱爲GuiPoc)。我設法成功編譯了guipoc-html項目(使用Google -> GWT Compile),最終還是Run as -> Web Application。我嘗試使用mvn gae:run從guipoc/html目錄(在Cygwin的)按照維基,並得到了以下的輸出:PlayN骨架項目html模塊在maven中找不到核心模塊?

[INFO] 
[INFO] ------------------------------------------------------------------------ 
[INFO] Building GuiPoc HTML 0.0.1-SNAPSHOT 
[INFO] ------------------------------------------------------------------------ 
[INFO] 
[INFO] >>> maven-gae-plugin:0.9.2:run (default-cli) @ guipoc-html >>> 
[WARNING] The POM for com.mydomain.mynamespace:guipoc-core:jar:0.0.1-SNAPSHOT is missing, no dependency information available 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 0.619s 
[INFO] Finished at: Sun Jan 01 20:05:29 VET 2012 
[INFO] Final Memory: 8M/121M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal on project guipoc-html: Could not resolve dependencies for project com.mydomain.mynamespace:guipoc-html:war:0.0.1-SNAPSHOT: Failure to find com.mydomain.mynamespace:guipoc-core:jar:0.0.1-SNAPSHOT in http://forplay.googlecode.com/svn/mavenrepo was cached in the local repository, resolution will not be reattempted until the update interval of forplay-legacy has elapsed or updates are forced -> [Help 1] 
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. 
[ERROR] Re-run Maven using the -X switch to enable full debug logging. 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles: 
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException 

實際問題: 我不明白爲什麼它尋找的依賴系統存儲庫而不是本地目錄。我究竟做錯了什麼?我是否需要在我的pom.xml文件中更改某些內容?在我的C:\ Users \ MyName.m2目錄下創建一個settings.xml並設置一些東西?

這裏是guipoc/HTML/pom.xml中的含量:

<?xml version="1.0" encoding="UTF-8"?> 
<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/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <parent> 
    <groupId>com.mydomain.mynamespace</groupId> 
    <artifactId>guipoc</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    </parent> 

    <artifactId>guipoc-html</artifactId> 
    <packaging>war</packaging> 
    <name>GuiPoc HTML</name> 

    <properties> 
    <gwt.module>com.mydomain.mynamespace.GuiPoc</gwt.module> 
    <gwt.name>guipoc</gwt.name> 
    <!-- Desired Google App Engine SDK version --> 
    <gae.version>1.6.0</gae.version> 
    </properties> 

    <dependencies> 
    <dependency> 
     <groupId>com.mydomain.mynamespace</groupId> 
     <artifactId>guipoc-core</artifactId> 
     <version>${project.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>com.googlecode.playn</groupId> 
     <artifactId>playn-html</artifactId> 
     <version>${playn.version}</version> 
    </dependency> 
    </dependencies> 

    <build> 
    <plugins> 
     <plugin> 
     <groupId>org.codehaus.mojo</groupId> 
     <artifactId>gwt-maven-plugin</artifactId> 
     </plugin> 
     <plugin> 
     <artifactId>maven-eclipse-plugin</artifactId> 
     <version>2.8</version> 
     <configuration> 
      <downloadSources>true</downloadSources> 
      <downloadJavadocs>false</downloadJavadocs> 
      <wtpversion>2.0</wtpversion> 
      <additionalBuildcommands> 
      <buildCommand> 
       <name>com.google.gwt.eclipse.core.gwtProjectValidator</name> 
      </buildCommand> 
      </additionalBuildcommands> 
      <additionalProjectnatures> 
      <projectnature>com.google.gwt.eclipse.core.gwtNature</projectnature> 
      <projectnature>com.google.appengine.eclipse.core.gaeNature</projectnature> 
      </additionalProjectnatures> 
     </configuration> 
     </plugin> 
     <plugin> 
     <groupId>net.kindleit</groupId> 
     <artifactId>maven-gae-plugin</artifactId> 
     <version>0.9.2</version> 
     <dependencies> 
      <!-- 
      Declare explicit dependency on gae-runtime here, 
      so we can specify the App Engine SDK version 
      --> 
      <dependency> 
      <groupId>net.kindleit</groupId> 
      <artifactId>gae-runtime</artifactId> 
      <version>${gae.version}</version> 
      <type>pom</type> 
      </dependency> 
     </dependencies> 
     </plugin> 
    </plugins> 
    </build> 
</project> 

這裏是guipoc /型芯/ pom.xml中的含量:

<?xml version="1.0" encoding="UTF-8"?> 
<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/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <parent> 
    <groupId>com.mydomain.mynamespace</groupId> 
    <artifactId>guipoc</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    </parent> 

    <artifactId>guipoc-core</artifactId> 
    <packaging>jar</packaging> 
    <name>GuiPoc Core</name> 

    <dependencies> 
    <dependency> 
     <groupId>com.googlecode.playn</groupId> 
     <artifactId>playn-core</artifactId> 
     <version>${playn.version}</version> 
    </dependency> 
    </dependencies> 

    <build> 
    <plugins> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-source-plugin</artifactId> 
     </plugin> 
    </plugins> 

    <resources> 
     <!-- include the source files in our main jar for use by GWT --> 
     <resource> 
     <directory>${project.build.sourceDirectory}</directory> 
     </resource> 
     <!-- and continue to include our standard resources --> 
     <resource> 
     <directory>${basedir}/src/main/resources</directory> 
     </resource> 
    </resources> 
    </build> 
</project> 

這裏是guipoc的內容/pom.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<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/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <parent> 
    <groupId>com.googlecode.playn</groupId> 
    <artifactId>playn-project</artifactId> 
    <version>1.0.3</version> 
    </parent> 

    <groupId>com.mydomain.mynamespace</groupId> 
    <artifactId>guipoc</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>pom</packaging> 
    <name>GuiPoc Metaproject</name> 

    <properties> 
    <playn.version>1.0.3</playn.version> 
    </properties> 

    <modules> 
    <module>core</module> 
    <module>java</module> 
    <module>html</module> 
    <module>android</module> 
    </modules> 
    <dependencies> 
    <dependency> 
     <groupId>com.sun</groupId> 
     <artifactId>tools</artifactId> 
     <version>1.6</version> 
     <scope>system</scope> 
     <systemPath>C:\Program Files\Java\jdk1.7.0_02\lib\tools.jar</systemPath> 
    </dependency> 
    </dependencies> 
</project> 

回答

3

不幸的是,Maven對多模塊項目並不太聰明。標準PlayN項目(包括你)具有以下模塊結構:

top 
+- core 
+- html (depends on core) 
+- java (depends on core) 
+- android, flash, etc. 

當你在top目錄,並調用Maven的時候,它會讀取所有子模塊的POM和「知道」所有這些,將正確設置類路徑,以便在編譯和運行時看到適當的classes目錄。

但是,如果進入目錄並調用Maven,則不再「知道」所有子模塊。所有它知道是html POM,當它看到一個依賴其他的事(如在這種情況下core模塊),它通過標準的依賴解析過程,這就是:

  1. 檢查本地Maven倉庫~/.m2/repository
  2. 檢查在POM中明確指定的存儲庫。
  3. 檢查Maven中心。

當您想要在某個子模塊項目中運行命令時,必須安排從頂級項目執行該命令。這就是爲什麼從命令行進行測試需要從頂層目錄運行mvn test -P test-javamvn test -P test-html,而不是僅僅進入javahtml目錄並運行mvn test

不幸的是,我們用於使從命令行測試Java或HTML子模塊成爲可能的技巧不適用於gae:run。因此,在這種情況下,您必須先調用gae:run(並且實際上每次要使用gae:run進行測試時都要這樣做),首先將項目工件安裝到本地Maven存儲庫中,以解決Maven的侷限性。這是完成,像這樣:

cd top 
mvn install 
cd html 
mvn gae:run 

如果從調用的Maven這將是巨大的,如果Maven的足夠聰明來檢測,它是在一個子模塊的目錄中運行,並自動解決它會以同樣的方式同胞的依賴頂級項目目錄。唉,聰明是一個形容詞,在討論Maven時很少適用。

+0

這最終在一些其他的安裝正確的Android SDK版本並運行'mvn gae:unpack'來下載相應的appengine SDK之後有效。非常感謝。 – 2012-01-15 17:47:21