2010-11-04 520 views
2

這是我在pom.xml爲什麼servlet-api.jar將其狀態從測試轉換爲編譯?

<dependency> 
    <groupId>com.sun.jersey.jersey-test-framework</groupId> 
    <artifactId>jersey-test-framework-grizzly</artifactId> 
    <version>1.4</version> 
    <scope>test</scope> 
</dependency> 

這是我mvn --debug war:war後看到:

[...] 
[DEBUG] com.sun.jersey.jersey-test-framework:jersey-test-framework-grizzly:jar:1.4:test 
[DEBUG]  com.sun.jersey.jersey-test-framework:jersey-test-framework-core:jar:1.4:test 
[DEBUG]   org.glassfish:javax.servlet:jar:3.0-b66:test 
[DEBUG]  com.sun.grizzly:grizzly-servlet-webserver:jar:1.9.18-i:test 
[DEBUG]   com.sun.grizzly:grizzly-http:jar:1.9.18-i:test 
[DEBUG]    com.sun.grizzly:grizzly-framework:jar:1.9.18-i:test 
[DEBUG]    com.sun.grizzly:grizzly-rcm:jar:1.9.18-i:test 
[DEBUG]    com.sun.grizzly:grizzly-portunif:jar:1.9.18-i:test 
[DEBUG]   com.sun.grizzly:grizzly-http-servlet:jar:1.9.18-i:test 
[DEBUG]    com.sun.grizzly:grizzly-utils:jar:1.9.18-i:test 
[DEBUG]   javax.servlet:servlet-api:jar:2.5:compile 
[...] 

,請注意最後一行。爲什麼它不是"test",而是"compile"

PS。確實很奇怪。這是我的完整pom.xml(對不起,這不是短期):

[...] 
<dependencies> 
    <dependency> 
    <groupId>junit</groupId> 
    <artifactId>junit</artifactId> 
    <version>4.7</version> <!-- 10 Sep 2010 --> 
    <scope>test</scope> 
    </dependency> 
    <dependency> 
    <groupId>xom</groupId> 
    <artifactId>xom</artifactId> 
    <version>1.2.5</version> <!-- 13 Oct 2010 --> 
    </dependency> 
    <dependency> 
    <groupId>org.mockito</groupId> 
    <artifactId>mockito-all</artifactId> 
    <version>1.8.5</version> <!-- 9 Oct 2010 --> 
    <scope>test</scope> 
    </dependency> 
    <dependency> 
    <groupId>org.apache.commons</groupId> 
    <artifactId>commons-io</artifactId> 
    <version>1.3.2</version> <!-- 9 Oct 2010 --> 
    <scope>test</scope> 
    </dependency> 
    <dependency> 
    <groupId>joda-time</groupId> 
    <artifactId>joda-time</artifactId> 
    <version>1.6.2</version> <!-- 12 Oct 2010 --> 
    </dependency> 
    <dependency> 
    <groupId>commons-httpclient</groupId> 
    <artifactId>commons-httpclient</artifactId> 
    <version>3.1</version> <!-- 2 Nov 2010 --> 
    </dependency> 
    <dependency> 
    <groupId>com.sun.jersey</groupId> 
    <artifactId>jersey-server</artifactId> 
    <!-- version see below in dependencyManagement section --> 
    </dependency> 
    <dependency> 
    <groupId>com.sun.jersey</groupId> 
    <artifactId>jersey-client</artifactId> 
    <!-- version see below in dependencyManagement section --> 
    </dependency> 
    <dependency> 
    <groupId>com.sun.jersey.jersey-test-framework</groupId> 
    <artifactId>jersey-test-framework-grizzly</artifactId> 
    <!-- version see below in dependencyManagement section --> 
    </dependency> 
    <dependency> 
    <groupId>org.hibernate</groupId> 
    <artifactId>hibernate-entitymanager</artifactId> 
    <!-- version see below in dependencyManagement section --> 
    </dependency> 
    <dependency> 
    <groupId>org.apache.openejb</groupId> 
    <artifactId>openejb-ejbd</artifactId> 
    <!-- version see below in dependencyManagement section --> 
    </dependency> 
    <dependency> 
    <groupId>org.slf4j</groupId> 
    <artifactId>slf4j-jdk14</artifactId> 
    <!-- version see below in dependencyManagement section --> 
    </dependency> 
    <dependency> 
    <groupId>hsqldb</groupId> 
    <artifactId>hsqldb</artifactId> 
    <!-- version see below in dependencyManagement section --> 
    </dependency> 
    <dependency> 
    <groupId>javax</groupId> 
    <artifactId>javaee-api</artifactId> 
    <version>6.0</version> <!-- 9 Oct 2010 --> 
    <scope>provided</scope> 
    </dependency> 
</dependencies> 

<dependencyManagement> 
    <dependencies> 
    <dependency> 
     <groupId>com.sun.jersey</groupId> 
     <artifactId>jersey-core</artifactId> 
     <version>${jersey.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>com.sun.jersey</groupId> 
     <artifactId>jersey-server</artifactId> 
     <version>${jersey.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>com.sun.jersey</groupId> 
     <artifactId>jersey-client</artifactId> 
     <version>${jersey.version}</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>com.sun.jersey.jersey-test-framework</groupId> 
     <artifactId>jersey-test-framework-grizzly</artifactId> 
     <version>${jersey.version}</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-entitymanager</artifactId> 
     <version>${hibernate.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.openejb</groupId> 
     <artifactId>openejb-ejbd</artifactId> 
     <version>3.1.3</version> <!-- 26 October 2010 --> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>slf4j-jdk14</artifactId> 
     <version>1.4.2</version> <!-- 29 oct 2010 --> 
    </dependency> 
    <dependency> 
     <groupId>hsqldb</groupId> 
     <artifactId>hsqldb</artifactId> 
     <version>1.8.0.10</version> <!-- 12 October 2010 --> 
     <scope>test</scope> 
    </dependency> 
    </dependencies> 
</dependencyManagement> 
[...] 

這是怎麼maven-war-plugin配置:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-war-plugin</artifactId> 
    <version>2.0</version> 
    <configuration> 
    <archive> 
     <manifestEntries> 
     <SCM-Revision>${buildNumber}</SCM-Revision> 
     </manifestEntries> 
    </archive> 
    </configuration> 
</plugin> 
+0

你有沒有的javax.servlet:servlet的API中:jar:2.5作爲其一部分的? – Buhb 2010-11-04 15:26:17

+0

@Buhb請參閱我的問題的更新版本 – yegor256 2010-11-04 16:14:55

+0

您是否配置了帶有servlet-api相關性的maven-war-plugin? – 2010-11-04 16:16:25

回答

0

這是我做了什麼來解決這個問題:

[...] 
<dependency> 
    <groupId>javax.servlet</groupId> 
    <artifactId>jsp-api</artifactId> 
    <version>2.0</version> 
    <scope>provided</scope> 
    <exclusions> 
    <exclusion> 
     <groupId>javax.servlet</groupId> 
     <artifactId>servlet-api</artifactId> 
    </exclusion> 
    </exclusions> 
</dependency> 
[...] 
1

這是非常非常奇怪的,我沒有得到相同的輸出上運行時mvn--debug

 
$ mvn --debug compile 
... 
[DEBUG] com.sun.jersey.jersey-test-framework:jersey-test-framework-grizzly:jar:1.4:test 
[DEBUG]  com.sun.jersey.jersey-test-framework:jersey-test-framework-core:jar:1.4:test 
[DEBUG]   com.sun.jersey:jersey-server:jar:1.4:test 
[DEBUG]    com.sun.jersey:jersey-core:jar:1.4:test 
[DEBUG]    asm:asm:jar:3.1:test 
[DEBUG]   com.sun.jersey:jersey-client:jar:1.4:test 
[DEBUG]   org.glassfish:javax.servlet:jar:3.0-b66:test 
[DEBUG]  com.sun.grizzly:grizzly-servlet-webserver:jar:1.9.18-i:test 
[DEBUG]   com.sun.grizzly:grizzly-http:jar:1.9.18-i:test 
[DEBUG]    com.sun.grizzly:grizzly-framework:jar:1.9.18-i:test 
[DEBUG]    com.sun.grizzly:grizzly-rcm:jar:1.9.18-i:test 
[DEBUG]    com.sun.grizzly:grizzly-portunif:jar:1.9.18-i:test 
[DEBUG]   com.sun.grizzly:grizzly-http-servlet:jar:1.9.18-i:test 
[DEBUG]    com.sun.grizzly:grizzly-utils:jar:1.9.18-i:test 
[DEBUG]   javax.servlet:servlet-api:jar:2.5:test 
... 

這是一致的與dependency:tree

 
$ mvn dependency:tree 
[INFO] Scanning for projects... 
... 
[INFO] \- com.sun.jersey.jersey-test-framework:jersey-test-framework-grizzly:jar:1.4:test 
[INFO] +- com.sun.jersey.jersey-test-framework:jersey-test-framework-core:jar:1.4:test 
[INFO] | +- com.sun.jersey:jersey-server:jar:1.4:test 
[INFO] | | +- com.sun.jersey:jersey-core:jar:1.4:test 
[INFO] | | \- asm:asm:jar:3.1:test 
[INFO] | +- com.sun.jersey:jersey-client:jar:1.4:test 
[INFO] | \- org.glassfish:javax.servlet:jar:3.0-b66:test 
[INFO] \- com.sun.grizzly:grizzly-servlet-webserver:jar:1.9.18-i:test 
[INFO]  +- com.sun.grizzly:grizzly-http:jar:1.9.18-i:test 
[INFO]  | +- com.sun.grizzly:grizzly-framework:jar:1.9.18-i:test 
[INFO]  | +- com.sun.grizzly:grizzly-rcm:jar:1.9.18-i:test 
[INFO]  | \- com.sun.grizzly:grizzly-portunif:jar:1.9.18-i:test 
[INFO]  +- com.sun.grizzly:grizzly-http-servlet:jar:1.9.18-i:test 
[INFO]  | \- com.sun.grizzly:grizzly-utils:jar:1.9.18-i:test 
[INFO]  \- javax.servlet:servlet-api:jar:2.5:test 
... 

servlet-api工件的預期範圍爲test

您是否將servlet-api聲明爲依賴項,並且某個地方的範圍爲compile?這是我能夠複製的唯一途徑。


更新:我轉載粘貼您提供所有的依賴後mvn --debug輸出。也就是說,我不知道如何解釋執行maven-compiler-plugin時打印的這個輸出。還要注意,從dependency:tree不同:

 
$ mvn dependency:tree 
[INFO] Scanning for projects... 
... 
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ Q4098082 --- 
[INFO] com.stackoverflow:Q4098082:jar:1.0-SNAPSHOT 
[INFO] +- junit:junit:jar:4.7:test 
[INFO] +- xom:xom:jar:1.2.5:compile 
[INFO] | +- xml-apis:xml-apis:jar:1.3.03:compile 
[INFO] | +- xerces:xercesImpl:jar:2.8.0:compile 
[INFO] | \- xalan:xalan:jar:2.7.0:compile 
[INFO] +- org.mockito:mockito-all:jar:1.8.5:test 
[INFO] +- org.apache.commons:commons-io:jar:1.3.2:test 
[INFO] +- joda-time:joda-time:jar:1.6.2:compile 
[INFO] +- commons-httpclient:commons-httpclient:jar:3.1:compile 
[INFO] | +- commons-logging:commons-logging:jar:1.0.4:compile 
[INFO] | \- commons-codec:commons-codec:jar:1.2:compile 
[INFO] +- com.sun.jersey:jersey-server:jar:1.4:compile 
[INFO] | +- com.sun.jersey:jersey-core:jar:1.4:compile 
[INFO] | \- asm:asm:jar:3.1:compile 
[INFO] +- com.sun.jersey:jersey-client:jar:1.4:test 
[INFO] +- com.sun.jersey.jersey-test-framework:jersey-test-framework-grizzly:jar:1.4:test 
[INFO] | +- com.sun.jersey.jersey-test-framework:jersey-test-framework-core:jar:1.4:test 
[INFO] | | \- org.glassfish:javax.servlet:jar:3.0-b66:test 
[INFO] | \- com.sun.grizzly:grizzly-servlet-webserver:jar:1.9.18-i:test 
[INFO] |  +- com.sun.grizzly:grizzly-http:jar:1.9.18-i:test 
[INFO] |  | +- com.sun.grizzly:grizzly-framework:jar:1.9.18-i:test 
[INFO] |  | +- com.sun.grizzly:grizzly-rcm:jar:1.9.18-i:test 
[INFO] |  | \- com.sun.grizzly:grizzly-portunif:jar:1.9.18-i:test 
[INFO] |  +- com.sun.grizzly:grizzly-http-servlet:jar:1.9.18-i:test 
[INFO] |  | \- com.sun.grizzly:grizzly-utils:jar:1.9.18-i:test 
[INFO] |  \- javax.servlet:servlet-api:jar:2.5:test 
[INFO] +- org.hibernate:hibernate-entitymanager:jar:3.5.6-Final:compile 
[INFO] | +- org.hibernate:hibernate-core:jar:3.5.6-Final:compile 
[INFO] | | +- antlr:antlr:jar:2.7.6:compile 
[INFO] | | +- commons-collections:commons-collections:jar:3.1:compile 
[INFO] | | +- dom4j:dom4j:jar:1.6.1:compile 
[INFO] | | \- javax.transaction:jta:jar:1.1:compile 
[INFO] | +- org.hibernate:hibernate-annotations:jar:3.5.6-Final:compile 
[INFO] | | \- org.hibernate:hibernate-commons-annotations:jar:3.2.0.Final:compile 
[INFO] | +- cglib:cglib:jar:2.2:compile 
[INFO] | +- javassist:javassist:jar:3.9.0.GA:compile 
[INFO] | +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.0.Final:compile 
[INFO] | \- org.slf4j:slf4j-api:jar:1.5.8:compile 
[INFO] +- org.apache.openejb:openejb-ejbd:jar:3.1.3:test 
[INFO] | +- org.apache.openejb:javaee-api:jar:5.0-3:test 
[INFO] | +- org.apache.openejb:openejb-core:jar:3.1.3:test 
[INFO] | | +- log4j:log4j:jar:1.2.12:test 
[INFO] | | +- org.apache.openejb:ejb31-api-experimental:jar:3.1.3:test 
[INFO] | | +- org.apache.openejb:openejb-api:jar:3.1.3:test 
[INFO] | | +- org.apache.openejb:openejb-javaagent:jar:3.1.3:test 
[INFO] | | +- org.apache.openejb:openejb-jee:jar:3.1.3:test 
[INFO] | | | +- org.codehaus.woodstox:wstx-asl:jar:3.2.0:test 
[INFO] | | | | \- stax:stax-api:jar:1.0.1:test 
[INFO] | | | \- com.sun.xml.bind:jaxb-impl:jar:2.1.9:test 
[INFO] | | +- commons-cli:commons-cli:jar:1.1:test 
[INFO] | | +- org.apache.activemq:activemq-ra:jar:5.3.1:test 
[INFO] | | +- org.apache.activemq:activemq-core:jar:5.3.1:test 
[INFO] | | | +- commons-logging:commons-logging-api:jar:1.1:test 
[INFO] | | | +- org.apache.geronimo.specs:geronimo-jms_1.1_spec:jar:1.1.1:test 
[INFO] | | | +- org.apache.activemq:activeio-core:jar:3.1.2:test 
[INFO] | | | | \- org.apache.geronimo.specs:geronimo-j2ee-management_1.1_spec:jar:1.0.1:test 
[INFO] | | | +- org.apache.activemq:kahadb:jar:5.3.1:test 
[INFO] | | | +- org.apache.activemq.protobuf:activemq-protobuf:jar:1.0:test 
[INFO] | | | +- org.apache.geronimo.specs:geronimo-j2ee-management_1.0_spec:jar:1.0:test 
[INFO] | | | \- commons-net:commons-net:jar:2.0:test 
[INFO] | | +- org.apache.openjpa:openjpa:jar:1.2.1:test 
[INFO] | | | +- net.sourceforge.serp:serp:jar:1.13.1:test 
[INFO] | | | +- commons-lang:commons-lang:jar:2.1:test 
[INFO] | | | \- commons-pool:commons-pool:jar:1.3:test 
[INFO] | | +- org.apache.geronimo.components:geronimo-connector:jar:2.1:test 
[INFO] | | +- org.apache.geronimo.components:geronimo-transaction:jar:2.1:test 
[INFO] | | +- org.objectweb.howl:howl:jar:1.0.1-1:test 
[INFO] | | +- org.apache.geronimo.javamail:geronimo-javamail_1.4_mail:jar:1.2:test 
[INFO] | | +- org.apache.xbean:xbean-asm-shaded:jar:3.7:test 
[INFO] | | +- org.apache.xbean:xbean-finder-shaded:jar:3.7:test 
[INFO] | | +- org.apache.xbean:xbean-reflect:jar:3.7:test 
[INFO] | | +- org.apache.xbean:xbean-naming:jar:3.7:test 
[INFO] | | +- org.apache.openejb:commons-dbcp-all:jar:1.3-r699049:test 
[INFO] | | +- org.codehaus.swizzle:swizzle-stream:jar:1.0.1:test 
[INFO] | | +- wsdl4j:wsdl4j:jar:1.6.1:test 
[INFO] | | \- quartz:quartz:jar:1.5.2:test 
[INFO] | +- org.apache.openejb:openejb-server:jar:3.1.3:test 
[INFO] | +- org.apache.openejb:openejb-loader:jar:3.1.3:test 
[INFO] | \- org.apache.openejb:openejb-client:jar:3.1.3:test 
[INFO] +- org.slf4j:slf4j-jdk14:jar:1.4.2:compile 
[INFO] +- hsqldb:hsqldb:jar:1.8.0.10:test 
[INFO] \- javax:javaee-api:jar:6.0:provided 
... 

以上是我自己參考分析依賴性的範圍,它看起來是正確的。我不知道爲什麼maven-compiler-plugin在調試模式下輸出不同的結果,我不知道這是否是預期的,我從不關注輸出。

其他說明javax.servlet:servlet-api:jar:2.5位於執行compiler:testCompile期間的(巨大)測試類路徑中。

所以雖然我沒有一個完整的解釋,我不能發現任何副作用。

+0

這個問題我用'pom.xml'中的完整副本更新了我的問題。也許它會有幫助? – yegor256 2010-11-04 16:14:22

+0

你是否需要我的「完整解釋」,或者你的意思是其他一些信息來源? – yegor256 2010-11-04 17:51:57

+0

@Vincenzo:不,我的意思是*我*無法解釋運行'mvn --debug'時獲得的輸出。 – 2010-11-04 17:53:43

相關問題