我有几个Maven项目,每个项目都有一些共同的功能或至少是常见的配置/依赖项.我将其解压缩到一个公共的pom.xml,然后模块化了几个方面,例如持久性,Spring相关的依赖项等等 - 所有这些都在他们自己的模块中继承自这个父POM.
现在,"Common"是版本1.0.0,我有"ProjectA",我希望继承它.我收到警告:
版本与父版本重复
我不完全理解为什么这是一个警告.我以为我可以选择省略项目POM中的版本以继承该版本.(我为常见模块执行此操作 - 例如,common-spring为Spring应用程序添加了额外的常见依赖项,实际上,ProjectA实际上继承自common-spring.)
这不是一个选择吗?如果我将ProjectA版本更改为1.0.1或2.0.0一切都很好.
尝试使用Java 1.7的干净安装Apache Maven 3.1.0将Java库添加到本地Maven存储库.以下是添加Java归档文件的方法:
mvn install:install-file \
-DgroupId=net.sourceforge.ant4x \
-DartifactId=ant4x \
-Dversion=0.3.0 \
-Dfile=ant4x-0.3.0.jar \
-Dpackaging=jar
Run Code Online (Sandbox Code Playgroud)
这创建了以下目录结构:
$HOME/.m2/repository/net/sourceforge/ant4x/
??? 0.3.0
? ??? ant4x-0.3.0.jar.lastUpdated
? ??? ant4x-0.3.0.pom.lastUpdated
??? ant4x
??? 0.3.0
? ??? ant4x-0.3.0.jar
? ??? ant4x-0.3.0.pom
? ??? _remote.repositories
??? maven-metadata-local.xml
Run Code Online (Sandbox Code Playgroud)
项目的pom.xml
文件引用依赖项目(上面的树),如下所示:
<properties>
<java-version>1.5</java-version>
<net.sourceforge.ant4x-version>0.3.0</net.sourceforge.ant4x-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
...
<dependency>
<groupId>net.sourceforge</groupId>
<artifactId>ant4x</artifactId>
<version>${net.sourceforge.ant4x-version}</version>
<scope>provided</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
运行后mvn compile
,返回以下错误(完全登录Pastebin):
[ERROR] Failed to execute goal on project ant4docbook: Could not resolve dependencies for project net.sourceforge:ant4docbook:jar:0.6-SNAPSHOT: Failure …
Run Code Online (Sandbox Code Playgroud) 我正在安装一个具有 Maven 依赖项的包,并在尝试清理它时收到 DependencyResolutionException。克隆它后,我导航到该目录并运行以下命令以安装它,没有错误:
mvn install:install-file -Dfile=./lib/massbank.jar -DgroupId=massbank -DartifactId=massbank -Dversion=1.0 -Dpackaging=jar
mvn install:install-file -Dfile=./lib/metfusion.jar -DgroupId=de.ipbhalle.msbi -DartifactId=metfusion -Dversion=1.0 -Dpackaging=jar
Run Code Online (Sandbox Code Playgroud)
然后:
mvn clean package
Run Code Online (Sandbox Code Playgroud)
具有以下控制台输出:
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------< MassBank2NIST:MassBank2NIST >---------------------
[INFO] Building MassBank2NIST 0.0.2-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.450 s
[INFO] Finished at: 2021-04-07T01:08:28-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project MassBank2NIST: Could not resolve dependencies for project MassBank2NIST:MassBank2NIST:jar:0.0.2-SNAPSHOT: Failed to collect dependencies at edu.ucdavis.fiehnlab.splash:core:jar:1.8: Failed …
Run Code Online (Sandbox Code Playgroud) 我试图添加一些过滤到应用程序上下文文件,该文件驻留在WEB-INF目录中.
我在文件夹/ src/main/resources中有要过滤的文件(xmlgateway-context.xml).
我在文件夹src/main/filters中有属性文件(config-e05.properties)
我的POM设置如下:
<!-- environment profiles -->
<profiles>
<profile>
<id>e04</id>
<properties>
<targetenv>e04</targetenv>
</properties>
</profile>
<profile>
<id>e05</id>
<properties>
<targetenv>e05</targetenv>
</properties>
</profile>
</profiles>
<!-- build settings (filtering) -->
<build>
<filters>
<filter>src/main/filters/config-${targetenv}.properties</filter>
</filters>
<resources>
<resource>
<targetPath>WEB-INF</targetPath>
<filtering>true</filtering>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
Run Code Online (Sandbox Code Playgroud)
这将正确安装mvn,但是当我打开输出war文件时,我希望文件xmlgateway-context.xml位于/ WEB-INF目录中,但它最终位于/ WEB-INF/classes/WEB文件夹中-INF.
如何将此文件放到正确的位置.
或者,我可以将应用程序上下文放在不同的位置并在那里引用它.
我有一个Gradle项目,我正在使用maven-publisher插件将我的android库安装到maven local和maven repo.
这可行,但生成的pom.xml不包含任何依赖项信息.是否有解决方法来包含该信息,或者我是否被迫返回maven插件并执行所需的所有手动配置?
研究我意识到我没有告诉出版物依赖的位置,我只是指定输出/工件,所以我需要一种方法将它链接MavenPublication
到依赖项,但我还没有找到如何在文档.
------------------------------------------------------------ Gradle 1.10 ------------------------------------------------------------ Build time: 2013-12-17 09:28:15 UTC Build number: none Revision: 36ced393628875ff15575fa03d16c1349ffe8bb6 Groovy: 1.8.6 Ant: Apache Ant(TM) version 1.9.2 compiled on July 8 2013 Ivy: 2.2.0 JVM: 1.7.0_60 (Oracle Corporation 24.60-b09) OS: Mac OS X 10.9.2 x86_64
相关的build.gradle部分
//...
apply plugin: 'android-library'
apply plugin: 'robolectric'
apply plugin: 'maven-publish'
//...
repositories {
mavenLocal()
maven {
name "myNexus"
url myNexusUrl
}
mavenCentral()
}
//...
android.libraryVariants
publishing {
publications { …
Run Code Online (Sandbox Code Playgroud) 调用maven构建来指定备用文件来代替标准pom.xml文件名时是否存在参数?
基本上,我需要使用各种配置来运行我的maven构建的测试目标.现在我不得不使用外部脚本来更新具有此配置的标准pom,然后恢复该文件.我宁愿只能维护几个单独的配置文件,并使用我需要的特定文件调用maven.
我想知道的是,是否有某种方法可以覆盖pom.xml,例如
mvn clean test (uses standard pom.xml)
mvn clean test -Dmaven.source=alternate.xml
mvn clean test -Dmaven.source=alternate2.xml
Run Code Online (Sandbox Code Playgroud)
这可能吗?
我正在尝试让Project B下拉(并解压缩)由Project A构建并部署到远程存储库的ZIP .
使用maven-assembly-plugin
包装类型创建并附加ZIP pom
:
<artifactId>project-a</artifactId>
<name>ZIP</name>
<description>Used by Project B</description>
<packaging>pom</packaging>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>distribution-package</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/assembly/scripts.xml</descriptor>
</descriptors>
<tarLongFileMode>gnu</tarLongFileMode>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
试图从项目B的pom中拉下来maven-dependency-plugin
:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-scripts</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/staging</outputDirectory>
<stripVersion>true</stripVersion>
<artifactItems>
<artifactItem>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>
<overWrite>true</overWrite>
<type>zip</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
失败了: [ERROR] Failed to execute goal on project ...: …
zip pom.xml maven maven-assembly-plugin maven-dependency-plugin
在Windows环境中,您将在C:\ Users\user_name位置具有.m2文件夹,并且您将settings.xml文件复制到该文件夹,以便设置代理设置和nexus存储库位置等.
那么我必须在Ubuntu环境上做什么才能在安装maven之后获得类似的设置.
我正在努力在项目中获取rpm-maven插件设置.在我们的暂存和生产环境中,构建发生在Red Hat盒子上,但是我们有几个用于开发和测试的Windows盒子,所以我希望RPM构建过程成为仅在有一个盒子上的活动的配置文件的一部分rpmbuild已安装.
这是我第一次尝试激活条件:
<activation>
<os>
<family>unix</family>
</os>
<file>
<exists>/usr/bin/rpmbuild</exists>
</file>
</activation>
Run Code Online (Sandbox Code Playgroud)
我最初的测试只涉及在Windows机箱上构建并构建在CentOS机箱上,两者都给了我预期的结果.后来,这个版本在没有rpmbuild的Linux机器上破解了.看起来像这样的两个条件不受支持.是这样的吗?我意识到我可能只是摆脱<os/>
元素并获得我想要的结果,但是为了将来参考是否有更好的方法来创建具有多个激活条件的配置文件?
在配置我的时候pom.xml
,我不得不配置一个插件.我发现的是<plugin>
标签可以插入其中一个<plugins>
或<pluginManagement>
元素.我很迷惑!
<plugins>
和之间有什么区别<pluginManagement>
?