2009-09-30 161 views
3

如果我將它添加到POM,它會創建一個循環依賴項?我試過了,看起來發生了什麼。這裏有一些我不理解的東西。不是在構建結束時創建的戰爭文件。Maven循環依賴?

<dependency> 
    <groupId>${project.groupId}</groupId> 
    <artifactId>mywebapp</artifactId> 
    <version>${project.version}</version> 
    <type>war</type> 
    <scope>provided</scope> 
</dependency> 

我的目錄結構是root/functest,root/mywebapp。

有效POM

[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>[email protected]</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] ------------------------------------------------------------------------ 
+1

小建議清理你的pom,讓你的生活在未來變得輕鬆。 如果您確實需要插件管理,請將其移至父pom。移動存儲庫和插件存儲庫。例如,如果您需要更改插件版本,則只需在一個位置更改插件版本即可。 – jassuncao 2009-09-30 09:05:10

回答

4

它只會創建一個循環依賴如果mywebapp取決於functest(或傳遞地依賴於它)。從名字我猜想functest是一個測試組件,所以不存在這種依賴。

正如你所看到的,它是有效的特性代入依賴聲明,如果它導致循環,Maven會構建失敗。

我想圍繞你的困惑「是不是在構建結束時創建war文件。」是因爲你期望構建失敗,因爲functest是在mywebapp之前構建的?請記住,Maven的訪問本地和遠程存儲庫,所以mywebapp任何以前的版本的結果將是在倉庫中。如果是這種情況,請嘗試從您的本地/遠程存儲庫中刪除mywebapp,我懷疑你會看到構建失敗,由於未解決的依賴。

+0

這樣做,我忘記了本地存儲庫的作用。非常感謝。祝你今天愉快。 – Ric 2009-09-30 10:53:53

1

如果我將此添加到POM,它會創建一個循環依賴項?

如果你指的是聚甲醛是functest模塊的POM,添加依賴於mywebapp模塊將建立一個循環依賴只有在mywebapp模塊已經依賴於functest模塊(這不應該是這裏的情況)正如Rich在另一個答案中所述。

我已經嘗試過了,似乎什麼事情發生。

你確定嗎?您的多模塊項目是否定義良好?你能告訴我們父母嗎?您能否提供從父項啓動maven時獲得的跟蹤?

[...]不是在構建結束時創建的war文件嗎?

那麼......這取決於你在做什麼。

如果您嚴格遵循Automated Smoke Tests With Selenium, Cargo, TestNG and Maven,請注意,作者並沒有真正涵蓋多模塊項目設置(我不是說他沒有這樣做,我只是說他不覆蓋那部分),但只是功能測試項目設置。他總是從functest目錄啓動maven,而不是作爲父pom的反應堆,並且在步驟7中通過貨物部署的webapp被視爲「外部」依賴。

現在,如果您正在開發自己的web應用程序,那麼在運行功能測試之前構建它真的很有意義。實際上,這將是「推薦」的方法。在你的情況,一定要申報mywebappfunctest依賴和這兩個項目作爲父POM,即類似的東西的模塊聲明(如果父POM是在一個父目錄):

... 
    <modules> 
    <module>mywebapp</module> 
    <module>functest</module> 
    </modules> 
    ...