首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Maven循环依赖?

Maven循环依赖?
EN

Stack Overflow用户
提问于 2009-09-30 08:44:08
回答 2查看 8.4K关注 0票数 4

如果我将其添加到POM中,它会创建循环依赖吗?我已经试过了,这似乎是发生了什么。有件事我不明白。不是在构建结束时创建的war文件。

代码语言:javascript
复制
 <dependency>
  <groupId>${project.groupId}</groupId>
  <artifactId>mywebapp</artifactId>
  <version>${project.version}</version>
  <type>war</type>
  <scope>provided</scope>
 </dependency>

我的目录结构是root/functest,root/mywebapp。

有效POM

代码语言:javascript
复制
    [INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'help'.
[INFO] org.grails: checking for updates from tapestry.javaforge
[WARNING] *** CHECKSUM FAILED - Checksum failed on download: local = 'ee0f52bc37051384f078f9706be9445b550ee4a6'; remote = 'a535436f42caf1ba0f9372328d2920372f30c842' - RETRYING
[WARNING] *** CHECKSUM FAILED - Checksum failed on download: local = 'ee0f52bc37051384f078f9706be9445b550ee4a6'; remote = 'a535436f42caf1ba0f9372328d2920372f30c842' - IGNORING
[INFO] org.apache.maven.plugins: checking for updates from tapestry.javaforge
[INFO] org.codehaus.mojo: checking for updates from tapestry.javaforge
[INFO] artifact org.apache.maven.plugins:maven-help-plugin: checking for updates from tapestry.javaforge
[INFO] ------------------------------------------------------------------------
[INFO] Building functional-tests
[INFO]    task-segment: [help:effective-pom] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] [help:effective-pom]
[INFO] 
Effective POMs, after inheritance, interpolation, and profiles are applied:

<?xml version="1.0" encoding="UTF-8"?>
<!-- ====================================================================== -->
<!--                                                                        -->
<!-- Generated by Maven Help Plugin on 9/30/09 10:41 AM                     -->
<!-- See: http://maven.apache.org/plugins/maven-help-plugin/                -->
<!--                                                                        -->
<!-- ====================================================================== -->

<!-- ====================================================================== -->
<!--                                                                        -->
<!-- Effective POM for project 'com.mycompany:functest:pom:1.0-SNAPSHOT'    -->
<!--                                                                        -->
<!-- ====================================================================== -->

<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>
    <artifactId>myapp</artifactId>
    <groupId>com.mycompany</groupId>
    <version>1.0-SNAPSHOT</version>
  </parent>
  <groupId>com.mycompany</groupId>
  <artifactId>functest</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>pom</packaging>
  <name>functional-tests</name>
  <url>http://www.mycompany.com/functest</url>
  <organization>
    <name>My Company Inc</name>
    <url>http://www.mycompany.com</url>
  </organization>
  <developers>
    <developer>
      <id>john.doe</id>
      <name>John Doe</name>
      <email>john.doe@mycompany.com</email>
    </developer>
  </developers>
  <build>
    <sourceDirectory>C:\Documents and Settings\ric\AutoSmokeTest\steps\step7\functest\src\main\java</sourceDirectory>
    <scriptSourceDirectory>src/main/scripts</scriptSourceDirectory>
    <testSourceDirectory>C:\Documents and Settings\ric\AutoSmokeTest\steps\step7\functest\src\it</testSourceDirectory>
    <outputDirectory>C:\Documents and Settings\ric\AutoSmokeTest\steps\step7\functest\target\classes</outputDirectory>
    <testOutputDirectory>C:\Documents and Settings\ric\AutoSmokeTest\steps\step7\functest\target\test-classes</testOutputDirectory>
    <resources>
      <resource>
        <mergeId>resource-0</mergeId>
        <directory>C:\Documents and Settings\ric\AutoSmokeTest\steps\step7\functest\src\main\resources</directory>
      </resource>
    </resources>
    <testResources>
      <testResource>
        <mergeId>resource-1</mergeId>
        <directory>C:\Documents and Settings\ric\AutoSmokeTest\steps\step7\functest\src\test\resources</directory>
      </testResource>
    </testResources>
    <directory>C:\Documents and Settings\ric\AutoSmokeTest\steps\step7\functest\target</directory>
    <finalName>functest-1.0-SNAPSHOT</finalName>
    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-antrun-plugin</artifactId>
          <version>1.3</version>
        </plugin>
        <plugin>
          <artifactId>maven-assembly-plugin</artifactId>
          <version>2.2-beta-2</version>
        </plugin>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>2.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>2.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-dependency-plugin</artifactId>
          <version>2.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.4</version>
        </plugin>
        <plugin>
          <artifactId>maven-ear-plugin</artifactId>
          <version>2.3.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-ejb-plugin</artifactId>
          <version>2.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-jar-plugin</artifactId>
          <version>2.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-javadoc-plugin</artifactId>
          <version>2.5</version>
        </plugin>
        <plugin>
          <artifactId>maven-plugin-plugin</artifactId>
          <version>2.4.3</version>
        </plugin>
        <plugin>
          <artifactId>maven-rar-plugin</artifactId>
          <version>2.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-release-plugin</artifactId>
          <version>2.0-beta-8</version>
        </plugin>
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>2.3</version>
        </plugin>
        <plugin>
          <artifactId>maven-site-plugin</artifactId>
          <version>2.0-beta-7</version>
        </plugin>
        <plugin>
          <artifactId>maven-source-plugin</artifactId>
          <version>2.0.4</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.4.3</version>
        </plugin>
        <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>2.1-alpha-2</version>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.0.2</version>
        <executions>
          <execution>
            <goals>
              <goal>testCompile</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <source>1.5</source>
          <target>1.5</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.4.3</version>
        <executions>
          <execution>
            <phase>integration-test</phase>
            <goals>
              <goal>test</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <suiteXmlFiles>
            <suiteXmlFile>src/it/testng.xml</suiteXmlFile>
          </suiteXmlFiles>
          <parallel>true</parallel>
          <threadCount>10</threadCount>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.codehaus.cargo</groupId>
        <artifactId>cargo-maven2-plugin</artifactId>
        <version>1.0.1-alpha-1</version>
        <executions>
          <execution>
            <id>start-container</id>
            <phase>pre-integration-test</phase>
            <goals>
              <goal>start</goal>
              <goal>deploy</goal>
            </goals>
            <configuration>
              <deployer>
                <deployables>
                  <deployable>
                    <groupId>com.mycompany</groupId>
                    <artifactId>mywebapp</artifactId>
                    <type>war</type>
                    <pingURL>http://localhost:8080/mywebapp/index.html</pingURL>
                    <pingTimeout>300000</pingTimeout>
                    <properties>
                      <context>mywebapp</context>
                    </properties>
                  </deployable>
                </deployables>
              </deployer>
            </configuration>
          </execution>
          <execution>
            <id>stop-container</id>
            <phase>post-integration-test</phase>
            <goals>
              <goal>stop</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <wait>false</wait>
          <container>
            <containerId>tomcat5x</containerId>
            <zipUrlInstaller>
              <url>http://www.apache.org/dist/tomcat/tomcat-5/v5.5.28/bin/apache-tomcat-5.5.28.zip</url>
              <installDir>${installDir}</installDir>
            </zipUrlInstaller>
            <output>C:\Documents and Settings\ric\AutoSmokeTest\steps\step7\functest\target/tomcat5x.log</output>
            <log>C:\Documents and Settings\ric\AutoSmokeTest\steps\step7\functest\target/cargo.log</log>
          </container>
          <configuration>
            <home>C:\Documents and Settings\ric\AutoSmokeTest\steps\step7\functest\target/tomcat5x/container</home>
            <properties>
              <cargo.logging>high</cargo.logging>
              <cargo.servlet.port>8080</cargo.servlet.port>
            </properties>
          </configuration>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-help-plugin</artifactId>
        <version>2.1</version>
      </plugin>
    </plugins>
  </build>
  <repositories>
    <repository>
      <releases>
        <enabled>false</enabled>
      </releases>
      <snapshots />
      <id>public-snapshots</id>
      <url>http://public-snapshots</url>
    </repository>
    <repository>
      <releases />
      <snapshots />
      <id>openqa-releases</id>
      <url>http://nexus.openqa.org/content/repositories/releases</url>
    </repository>
    <repository>
      <id>openqa</id>
      <url>http://maven.openqa.org</url>
    </repository>
    <repository>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Maven Repository Switchboard</name>
      <url>http://repo1.maven.org/maven2</url>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <releases>
        <enabled>false</enabled>
      </releases>
      <snapshots />
      <id>public-snapshots</id>
      <url>http://public-snapshots</url>
    </pluginRepository>
    <pluginRepository>
      <releases />
      <snapshots />
      <id>openqa-plugin</id>
      <url>http://nexus.openqa.org/content/repositories/releases</url>
    </pluginRepository>
    <pluginRepository>
      <releases />
      <snapshots />
      <id>another-plugin</id>
      <url>http://repo1.maven.org/maven2</url>
    </pluginRepository>
    <pluginRepository>
      <releases />
      <id>codehaus.snapshots</id>
      <url>http://snapshots.repository.codehaus.org/</url>
    </pluginRepository>
    <pluginRepository>
      <id>mortbay.repo</id>
      <url>http://www.mortbay.org/maven2/snapshot</url>
    </pluginRepository>
    <pluginRepository>
      <id>tapestry.javaforge</id>
      <url>http://howardlewisship.com/repository</url>
    </pluginRepository>
    <pluginRepository>
      <releases>
        <updatePolicy>never</updatePolicy>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Maven Plugin Repository</name>
      <url>http://repo1.maven.org/maven2</url>
    </pluginRepository>
  </pluginRepositories>
  <dependencies>
    <dependency>
      <groupId>com.mycompany</groupId>
      <artifactId>mywebapp</artifactId>
      <version>1.0-SNAPSHOT</version>
      <type>war</type>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.seleniumhq.selenium.server</groupId>
      <artifactId>selenium-server</artifactId>
      <version>1.0.1</version>
    </dependency>
    <dependency>
      <groupId>org.seleniumhq.selenium.client-drivers</groupId>
      <artifactId>selenium-java-client-driver</artifactId>
      <version>1.0.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.testng</groupId>
      <artifactId>testng</artifactId>
      <version>5.1</version>
      <classifier>jdk15</classifier>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <reporting>
    <outputDirectory>C:\Documents and Settings\ric\AutoSmokeTest\steps\step7\functest\target/site</outputDirectory>
  </reporting>
</project>

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3 seconds
[INFO] Finished at: Wed Sep 30 10:41:00 CEST 2009
[INFO] Final Memory: 7M/13M
[INFO] ------------------------------------------------------------------------
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2009-09-30 08:52:49

只有当mywebapp依赖于functest (或传递地依赖于它)时,它才会创建循环依赖。从名称上看,我猜测functest是一个测试组件,因此不会存在这样的依赖。

正如您所看到的,将属性替换到依赖声明中是有效的,如果Maven导致循环,则Maven将导致构建失败。

我猜您对“不是在构建结束时创建的war文件”感到困惑。是因为您希望构建失败,因为functest是在mywebapp之前构建的?请记住,Maven可以访问本地和远程存储库,因此以前构建的任何mywebapp的结果都将在存储库中可用。如果是这种情况,请尝试从本地/远程存储库中删除mywebapp,我怀疑您会看到由于未解析的依赖项而导致构建失败。

票数 4
EN

Stack Overflow用户

发布于 2009-09-30 10:41:34

如果我把这个添加到一个POM中,它会创建一个循环依赖吗?

如果您所指的pom是functest模块的pom,则仅当mywebapp模块已经依赖于mywebapp模块(这里不应该是这种情况)时,向functest模块添加依赖项才会创建循环依赖项,正如里奇在另一个答案中所述。

我已经试过了,这似乎是发生了什么。

真的吗?你的多模块项目定义好了吗?你能给我们看一下父母的pom吗?您能提供从家长启动maven时获得的跟踪吗?

...war文件不是在构建结束时创建的吗?

好吧..。这取决于你在做什么。

如果您严格遵循Automated Smoke Tests With Selenium, Cargo, TestNG and Maven,请注意,作者并没有真正介绍多模块项目设置(我并不是说他没有这样做,我只是说他没有介绍这一部分),而只是介绍了功能测试项目设置。他总是从functest目录启动maven,而不是从父pom中作为反应器启动,并且在step 7中由cargo部署的webapp被视为“外部”依赖项。

现在,如果您正在开发自己的are应用程序,那么在对其运行功能测试之前构建它是非常有意义的。实际上,这将是“推荐”的方法。在您的示例中,请确保将mywebapp声明为functest的依赖项,并将两个项目声明为父pom的模块,即类似于此(如果父pom位于父目录中):

代码语言:javascript
复制
  ...
  <modules>
    <module>mywebapp</module>
    <module>functest</module>
  </modules>
  ...
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1496824

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档