我只是在学习Maven,所以这可能很明显,但我找不到一个简单的方法来列出给定项目的每个maven生命周期阶段的相关目标.
我看到Maven默认生命周期阶段和相应的默认目标都记录在这里.到目前为止,我的理解是每个pom.xml都可以为每个生命周期阶段绑定其他目标.
那么,是否有一个mvn命令来确定将为给定项目的每个生命周期阶段运行的目标?如果没有,我想我只需要查看每个新maven项目的pom.xml来解决这个问题?
我以为我是一位经验丰富的Maven用户,但我对如何做到这一点有心理障碍!
我已经能够使用Maven插件SQL通过我已经定义并绑定插件处决下降,创建和安装一个架构在一个数据库pre-integration-test阶段.
不过,现在我想使用相同的SQL插件插入一些示例数据,每当我在命令行想要的 - 也就是说,没有绑定到任何生命周期的目标.有几组不同的样本数据,所以我想定义一些不同的执行.
但有没有办法通过使用执行ID从命令行运行其中一个执行?
截至今天,我的maven编译失败了.
[INFO] [ERROR] Unexpected
[INFO] java.lang.OutOfMemoryError: Java heap space
[INFO] at java.util.Arrays.copyOfRange(Arrays.java:2694)
[INFO] at java.lang.String.<init>(String.java:203)
[INFO] at java.lang.String.substring(String.java:1877)
Run Code Online (Sandbox Code Playgroud)
[错误]内存不足; 要增加内存量,请在启动时使用-Xmx标志(java -Xmx128M ...)
截至昨天,我已成功运行maven编译.
截至今天,我刚刚把我的堆增加到3 GB.另外,我只更改了2-3行代码,所以我不明白这个"内存不足"的错误.
vagrant@dev:/vagrant/workspace$ echo $MAVEN_OPTS
-Xms1024m -Xmx3000m -Dmaven.surefire.debug=-Xmx3000m
Run Code Online (Sandbox Code Playgroud)
编辑:我通过更改失败的模块的pom.xml尝试了海报的评论.但我得到了相同的maven构建错误.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<fork>true</fork>
<meminitial>1024m</meminitial>
<maxmem>2024m</maxmem>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud) 现在maven-3确实放弃了对<uniqueVersion> false </ uniqueVersion>的快照伪像的支持,似乎你真的需要使用带时间戳的SNAPSHOTS.特别是在内部使用maven 3的m2eclipse似乎受其影响,当SNAPSHOTS不是唯一时,更新快照不起作用.
以前将最佳快照设置为uniqueVersion = false 似乎是最佳做法
现在,切换到带时间戳的版本似乎没什么大问题,毕竟它们是由中央nexus存储库管理的,它可以在常规的intervalls中删除旧的快照.
问题是本地开发人员工作站.他们的本地存储库通过独特的快照很快变得非常大.
如何处理这个问题?
现在我看到了以下可能的解决方案:
保持本地存储库填满硬盘空间的最佳方法是什么?
更新:
为了验证beaviour并提供更多信息,我设置了一个小的nexus服务器,构建两个项目(a和b)并尝试:
A:
<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>de.glauche</groupId>
<artifactId>a</artifactId>
<version>0.0.1-SNAPSHOT</version>
<distributionManagement>
<snapshotRepository>
<id>nexus</id>
<name>nexus</name>
<url>http://server:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
</project>
Run Code Online (Sandbox Code Playgroud)
b:
<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>de.glauche</groupId>
<artifactId>b</artifactId>
<version>0.0.1-SNAPSHOT</version>
<distributionManagement>
<snapshotRepository>
<id>nexus</id>
<name>nexus</name>
<url>http://server:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
<repositories>
<repository>
<id>nexus</id>
<name>nexus</name>
<snapshots>
<enabled>true</enabled>
</snapshots>
<url>http://server:8081/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>de.glauche</groupId>
<artifactId>a</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency> …Run Code Online (Sandbox Code Playgroud) 我有以下由Maven 3.0.4运行的普通pom.
<?xml version="1.0" encoding="UTF-8"?>
<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.example</groupId>
<artifactId>test</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
</project>
Run Code Online (Sandbox Code Playgroud)
我试图在命令行中覆盖默认设置,如下所示:
mvn -Dproject.build.finalName=build clean package
Run Code Online (Sandbox Code Playgroud)
但是这被忽略了,我明白了test-1.0.jar.我试图更改另一个属性,如outputDirectory,directory,artifactId,但也失败了.
做这件事的正确方法是什么?
我在Mac Yosemite上使用Maven 3.3.3和Java 8.我有一个多模块项目.
<modules>
<module>first-module</module>
<module>my-module</module>
…
</modules>
Run Code Online (Sandbox Code Playgroud)
当我构建我的一个子模块,例如,上面的"my-module",使用"mvn clean install"时,构建尝试从我在〜/ .m2中定义的远程存储库下载子模块工件. /settings.xml文件.输出低于
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building my-module 87.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: https://my.remoterepository.com/nexus/content/repositories/snapshots/org/mainco/subco/first-module/87.0.0-SNAPSHOT/maven-metadata.xml
Downloading: http://download.java.net/maven/2/org/mainco/subco/first-module/87.0.0-SNAPSHOT/maven-metadata.xml
Downloaded: https://my.remoterepository.com/nexus/content/repositories/snapshots/org/mainco/subco/first-module/87.0.0-SNAPSHOT/maven-metadata.xml (788 B at 0.9 KB/sec)
Downloading: https://my.remoterepository.com/nexus/content/repositories/snapshots/org/mainco/subco/first-module/87.0.0-SNAPSHOT/first-module-87.0.0-20151104.200545-4.pom
Run Code Online (Sandbox Code Playgroud)
在尝试从远程存储库下载之前,如何强制Maven先检查我的本地〜/ .m2/repository?下面是我在〜/ .m2/settings.xml文件中定义远程存储库的地方......
<profile>
<id>releases</id>
<activation>
<property>
<name>!releases.off</name>
</property>
</activation>
<repositories>
<repository>
<id>releases</id>
<url>https://my.remoterepository.com/nexus/content/repositories/releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</profile>
<profile>
<id>snapshots</id>
<activation>
<property>
<name>!snapshots.off</name>
</property>
</activation>
<repositories>
<repository>
<id>snapshots</id>
<url>https://my.remoterepository.com/nexus/content/repositories/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
Run Code Online (Sandbox Code Playgroud)
编辑: …
在maven多模块项目中,我希望每个模块始终保持与父模块相同的版本,我通常在模块的pom.xml中执行以下操作:
<parent>
<groupId>com.groupId</groupId>
<artifactId>parentArtifactId</artifactId>
<version>1.1-SNAPSHOT</version>
</parent>
<groupId>com.groupId</groupId>
<artifactId>artifactId</artifactId>
<packaging>jar</packaging>
<version>${project.parent.version}</version>
<name>name</name>
Run Code Online (Sandbox Code Playgroud)
自从我开始使用maven 3.0-alpha-5以来,我收到了以下警告.
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.groupid.artifactId:name:jar:1.1-SNAPSHOT
[WARNING] 'version' contains an expression but should be a constant. @ com.groupid.artifactId:name::${project.parent.version}, /Users/whaley/path/to/project/child/pom.xml
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
Run Code Online (Sandbox Code Playgroud)
我很想知道将模块的版本绑定到父版本的真正问题是,如果有的话?或者这是一个一般警告的情况,当任何表达式,无论是否是project.parent.version,用于版本元素.
我正在尝试使用Maven构建一个简单的Java项目.在我的pom文件中,我声明JUnit 4.8.2是唯一的依赖项.仍然Maven坚持使用JUnit版本3.8.1.我如何解决它?
问题表现在编译失败:"package org.junit不存在".这是因为我的源代码中的import语句.JUnit 4.*中的正确包名称是org.junit.*,而在版本3中.*它是junit.framework.*
我想我已经在http://maven.apache.org/plugins/maven-surefire-plugin/examples/junit.html找到了关于问题根源的文档,但是那里的建议似乎是Maven专家的意思.我不明白该怎么做.
创建IntelliJ→New Project→Maven时,原型列表为空白,无论经过多长时间,都不会填充."加载原型列表..."继续,但似乎没有做太多.有什么建议?

来自的信息mvn -v:
Apache Maven 3.2.5 (NON-CANONICAL_2014-12-25T17:13:28_root; 2014-12-25T05:13:28-08:00)
Maven home: /opt/maven
Java version: 1.8.0_25, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-openjdk/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.17.6-1-arch", arch: "amd64", family: "unix"
Run Code Online (Sandbox Code Playgroud)
IntelliJ IDEA Professional 14.0.2
我正在尝试使用maven创建javadoc并且它失败了.执行验证时也会失败.
mvn verify
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
(...)
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/miquel/creaveu/createOmegaMatrix/src/main/java/edu/url/salle/gtm/hnm/dataStructures/HFrame.java:[6,23]
package org.junit does not exist
[ERROR] /home/miquel/creaveu/createOmegaMatrix/src/main/java/edu/url/salle/gtm/hnm/dataStructures/HFrame.java:[6,0]
static import only from classes and interfaces
(···)
Run Code Online (Sandbox Code Playgroud)
在我的pom.xml文件中,我有以下几行:
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我的本地存储库包含junit jar文件:
miquel@ubuntu:~/creaveu/createOmegaMatrix$ ls -l /home/miquel/.m2/repository/org/junit/junit/4.8.2/
total 248
**-rw-r--r-- 1 miquel miquel 237344 2012-09-13 11:01 junit-4.8.2.jar**
-rw-r--r-- 1 miquel miquel 236 2012-09-13 11:13 junit-4.8.2-javadoc.jar.lastUpdated
-rw-r--r-- 1 miquel miquel 0 2012-09-13 11:13 junit-4.8.2-javadoc.jar-not-available
-rw-r--r-- 1 miquel miquel 458 2012-09-12 18:35 junit-4.8.2.pom
-rw-r--r-- 1 miquel …Run Code Online (Sandbox Code Playgroud) maven-3 ×10
maven ×7
java ×2
junit4 ×2
artifacts ×1
command-line ×1
database ×1
intellij-14 ×1
junit ×1
junit3 ×1
maven-2 ×1
maven-plugin ×1
pom.xml ×1
repository ×1
testing ×1