PlayN骨架项目html模块在maven中找不到核心模块?

时间:2012-01-02 01:03:03

标签: google-app-engine maven playn

基于PlayN Getting Started wiki page我在eclipse中创建了一个骨架项目(称为GuiPoc)。我设法使guipoc-html项目成功编译(使用Google -> GWT Compile),最终成为Run as -> Web Application。我按照wiki尝试使用guipoc / html目录(在cygwin中)中的mvn gae:run,得到以下输出:

[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 / core / 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>

1 个答案:

答案 0 :(得分:3)

不幸的是,Maven对多模块项目并不太聪明。标准PlayN项目(包括您的项目)具有以下模块结构:

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

当你在top目录中,并且你调用Maven时,它会读取所有子模块POM并“知道”所有这些子模块并正确设置类路径,以便它们看到相应的{{1编译和运行时的目录。

但是如果你进入classes目录并在那里调用Maven,它就不再“了解”所有子模块。所有它知道的是html POM,当它看到其他任何东西的依赖关系时(比如本例中的html模块),它会经历标准的依赖关系解析过程,即:

  1. 检查本地Maven存储库core
  2. 检查POM中明确指定的存储库。
  3. 检查Maven Central。
  4. 如果您希望在其中一个子模块项目中运行命令,则必须安排从顶级项目执行此操作。这就是为什么从命令行进行测试涉及从顶级目录运行~/.m2/repositorymvn test -P test-java,而不是仅仅进入mvn test -P test-htmljava目录并运行html

    不幸的是,我们用来从命令行测试Java或HTML子模块的技巧不适用于mvn test。因此,在这种情况下,您必须首先在调用gae:run之前将项目工件安装到本地Maven存储库中来解决Maven的限制(事实上,每次要使用gae:run进行测试时都要这样做。是这样完成的:

    gae:run

    如果Maven足够智能,可以检测到它是在子模块目录中运行并自动解析兄弟依赖关系,就像从顶层项目目录调用Maven一样。唉,聪明是一个形容词,在谈论Maven时很少适用。