Rya*_*ach 2 java eclipse dependencies maven m2e
例如,如果我将BukkitApi jar作为maven项目的依赖项,并将detanecy范围设置为提供,编译,系统,运行时或测试
bukkitAPI将在哪些范围内包含在编译输出中?
简短版本:默认情况下,maven输出(在默认target
目录中)不包含除当前项目/模块的编译代码之外的任何内容.也就是说,没有任何依赖.
长(呃)版本:默认jar
包装,没有自定义阶段配置.这是maven在java项目中的行为方式:
compile
阶段:.java
在文件src/main/java/
目录中获取编译.classes
的文件target
目录.compile
范围的依赖关系将下载到本地存储库.package
阶段:同1,再加上你会得到一个jar
在文件target
目录install
阶段:同2,你会得到一个jar
在你的本地库文件.因此,.jar
默认情况下,来自依赖项的文件不包含在任何内容中!
现在,例如,使用assembly
插件在package
阶段的输出中包含依赖项(请参阅使用Maven包含jar中的依赖项),通常会得到以下默认行为:
provided
: 不包含compile
(默认):包含system
: 不包含runtime
:包括在内test
: 不包含查看此链接以供参考.
编辑:只需尝试使用不同的范围值的这个pom guice
,你会看到依赖关系包含在fake-1.0-SNAPSHOT-jar-with-dependencies.jar
范围是什么时(compile
和runtime
此示例不需要任何源文件)
<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>
<groupId>com.linagora</groupId>
<artifactId>fake</artifactId>
<version>1.0-SNAPSHOT</version>
<name>fake</name>
<dependencies>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>2.0</version>
<scope>compile</scope>
<!-- system scope needs 'systemPath' attribute as well
<systemPath>/path/to/guice/guice-3.0.jar</systemPath>
<scope>system</scope>
-->
<!-- <scope>runtime</scope> -->
<!-- <scope>test</scope> -->
<!-- <scope>provided</scope> -->
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3739 次 |
最近记录: |