dependencyManagement
和之间有什么区别dependencies
?我在Apache Maven网站上看过这些文档.似乎dependencyManagement
可以在其子模块中使用在其下定义的依赖项而不指定版本.
例如:
父项目(Pro-par)在以下内容下定义依赖项dependencyManagement
:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8</version>
</dependency>
</dependencies>
</dependencyManagement>
Run Code Online (Sandbox Code Playgroud)
然后在Pro-par的孩子,我可以使用junit:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
但是,我想知道是否有必要在父pom中定义junit?为什么不直接在所需的模块中定义它?
我有一个关于Bitbucket的项目.只提交了来源.为了将项目检索到新机器上,我在IntelliJ中使用了Version Control> Checkout from Version Control.
然后询问我是否要从此源创建一个新项目,我回复是.到现在为止还挺好.它为我创建了一个很好的小Java项目,由一个模块组成.
但是,我将此项目纳入IntelliJ的目标是将其转变为Maven项目.我无法在任何地方找到任何可以让我这样做的选项!
有没有办法让IntelliJ为我生成一个基本的空pom.xml,具有名称和artifactId以及存储库?或者,有没有办法将项目作为Maven项目导入?(每当我尝试从现有源创建项目时,它只给我一个Java项目的选项.)
我在netbeans上写了一个maven代码,它有大约2000多行.当我在netbeans上编译它时,一切都很好,但如果我想在命令行上运行它,我将得到这些错误:
generics are not supported in -source 1.3
(use -source 5 or higher to enable generics)
ArrayList<ArrayList<Integer>> list = new ArrayList<ArrayList<Integer>>();
generics are not supported in -source 1.3
(use -source 5 or higher to enable generics)
HashSet<Double> resid_List = new HashSet<Double>(Arrays.asList(resid_val));
generics are not supported in -source 1.3
(use -source 5 or higher to enable generics)
List<Integer> ind_ovlpList = new ArrayList<Integer>(Arrays.asList(ind_ovlp));
generics are not supported in -source 1.3
(use -source 5 or higher to enable generics)
public class ColumnComparator implements …
Run Code Online (Sandbox Code Playgroud) 这是我的pom文件的片段.
....
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
......
</configuration>
</execution>
</executions>
</plugin>
</plugins>
...
Run Code Online (Sandbox Code Playgroud)
我在命令中成功使用它
mvn install
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试将其封装到"pluginManagement"标签中时,maven-dependency-plugin
当我启动install
目标时停止工作.为什么"pluginManagement"标签会改变构建行为?或者我应该使用其他目标或选项?
查看文档http://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html,我们可以看到<scope>
标签下<dependency>
那是什么以及我们如何使用它来运行测试?
我使用maven作为构建工具.我已经设置了一个名为的环境变量env
.如何在pom.xml
文件中访问此环境变量的值?
我刚开始使用Maven,我被告知要mvn install
在特定的目录中进行操作.
到底mvn install
做了什么?
我认为它pom.xml
在当前文件夹中查找并开始按照该文件中指定的说明进行操作.那是对的吗?
使用IntelliJ 12,我有一个java项目,我使用maven和pom.xml.我的项目使用的是java8,但在导入项目时,似乎默认的项目语言级别已设置为6.
我可以将语言级别更改为8.0(F4 - >模块 - >语言级别)但是每次编辑我的pom.xml时,项目级别都会切换回"使用项目语言级别",我必须再次编辑此设置,再次.
是否需要添加到pom.xml以将默认语言级别设置为8.0?
我正在尝试构建一个我修改过的Hudson插件,它需要jdk1.6.这很好,但我不知道如何告诉maven不同的jdk在哪里.我在互联网上发现很少提及但它们似乎并不适用于我.有人建议添加一些配置,.m2/settings.xml
但我没有settings.xml
.另外,我不想对所有maven版本使用1.6.
我mvn
在cygwin中使用的一个问题是,如果这很重要的话.看来我应该能够在项目pom文件中制作规范,但是现有的pom非常简单.
那么底线是,有没有办法为maven的单个调用指定一个jdk?
可以通过<exclusions>
在a中声明一个元素来排除依赖项中的工件.<dependency>
但在这种情况下,需要排除从父项目继承的工件.正在讨论的POM摘录如下:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>jruby</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<artifactId>base</artifactId>
<groupId>es.uniovi.innova</groupId>
<version>1.0.0</version>
</parent>
<dependencies>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>ALL-DEPS</artifactId>
<version>1.0</version>
<scope>provided</scope>
<type>pom</type>
</dependency>
</dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)
base
工件,取决于 javax.mail:mail-1.4.jar
,并ALL-DEPS
取决于同一个库的另一个版本.由于这样的事实mail.jar
,从ALL-DEPS
存在于执行环境,虽然没有出口,碰撞与mail.jar
那对父母,这是作用域确定为存在compile
.
解决方案可能是从父POM中删除mail.jar,但是大多数继承base的项目都需要它(因为它是log4j的转换依赖项).所以我想做的是简单地从子项目中排除父项库,因为如果base
是依赖项而不是父项pom 可以这样做:
...
<dependency>
<artifactId>base</artifactId>
<groupId>es.uniovi.innova</groupId>
<version>1.0.0</version>
<type>pom<type>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
</exclusions>
</dependency>
...
Run Code Online (Sandbox Code Playgroud)