我已经在my pom.xmlmaven中配置了所有依赖项.当我发出命令时,mvn install我收到以下错误:
[INFO]插件管理器中执行目标的内部错误'org.apache.maven.plugins:maven-surefire-plugin:2.4.3:test':无法加载mojo'org.apache.maven.plugins:maven-surefire -plugin:2.4.3:在'插件'中测试'org.apache.maven.plugins:maven-surefire-plugin'.缺少必需的类:org/apache/maven/surefire/util/NestedCheckedException org.apache.maven.surefire.util.NestedCheckedException
我该如何解决这个问题?
dependencies maven-2 maven-plugin maven maven-dependency-plugin
当我构建一个多模块maven项目(使用mvn clean compile),其中一个依赖项(构建反应器的一部分)使用依赖项复制到另一个:复制,然后maven抱怨以下错误.
Artifact has not been packaged yet. When used on reactor artifact, copy should be executed after packaging: see MDEP-187 is thrown
这非常好,Maven无法复制依赖jar,因为它尚未打包,并且依赖性必须从本地项目而不是从存储库中解析.
让我们说项目A正在使用依赖项复制到项目B:复制目标.
现在,如果我将项目导入eclipse,生命周期映射的设置方式使得maven-jar-plugin在项目A上执行(这意味着A被打包),那么项目B仍抱怨同样的错误.我怎样才能摆脱这种情况.我不能忽视依赖:在m2e生命周期中复制,因为它是构建中的关键阶段.
ProjectA的pom文件:
<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>
<artifactId>projecta</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>com.coderplus.tests</groupId>
<artifactId>projectparent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<versionRange>[2.4,)</versionRange>
<goals>
<goal>jar</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
项目B的pom文件
<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 …Run Code Online (Sandbox Code Playgroud) 根据Maven依赖文档,所有编译依赖项都是明确列出的,而不是在编译时传递使用:
它的意思是[传递编译依赖项]应该是运行时范围,因此必须明确列出所有编译依赖项 - 但是,有一种情况,您依赖的库从另一个库扩展一个类,迫使您在编译时间.因此,编译时依赖性仍然是编译范围,即使它们是可传递的.
Spring Boot有一个"Starter"依赖的概念.从Spring Boot自己的文档(以及我在Spring Boot自己的示例和其他地方看到的许多使用示例)中可以清楚地看出,这些示例旨在传递大量其他依赖项,以便在运行时和编译时使用.Per Spring Boot的文档:
启动器是一组方便的依赖关系描述符,您可以在应用程序中包含这些描述符.您可以获得所需的所有Spring和相关技术的一站式服务,而无需搜索示例代码并复制粘贴的依赖描述符.例如,如果您想开始使用Spring和JPA进行数据库访问,只需在项目中包含spring-boot-starter-data-jpa依赖项,就可以了.
启动器包含许多依赖项,这些依赖项是使项目快速启动和运行所需的依赖项,以及一组受支持的托管传递依赖项.
使用这种机制传递引入编译范围的依赖关系似乎与Maven官方打算如何使用它们的意图不一致.使这一点非常清楚的一个地方是Maven 依赖:分析插件目标,它在直接使用Maven启动器依赖项时显示警告.例如,mvn dependency:analyze在Spring Boot自己的" Getting Started "示例上运行会生成以下输出:
[WARNING] Used undeclared dependencies found:
[WARNING] org.springframework:spring-web:jar:4.3.6.RELEASE:compile
[WARNING] org.springframework.boot:spring-boot-test:jar:1.5.1.RELEASE:test
[WARNING] org.springframework.boot:spring-boot-test-autoconfigure:jar:1.5.1.RELEASE:test
[WARNING] org.springframework:spring-test:jar:4.3.6.RELEASE:test
[WARNING] org.springframework.boot:spring-boot:jar:1.5.1.RELEASE:compile
[WARNING] org.hamcrest:hamcrest-library:jar:1.3:test
[WARNING] org.springframework:spring-context:jar:4.3.6.RELEASE:compile
[WARNING] junit:junit:jar:4.12:test
[WARNING] org.springframework.boot:spring-boot-autoconfigure:jar:1.5.1.RELEASE:compile
[WARNING] org.springframework:spring-beans:jar:4.3.6.RELEASE:compile
[WARNING] Unused declared dependencies found:
[WARNING] org.springframework.boot:spring-boot-starter-web:jar:1.5.1.RELEASE:compile
[WARNING] org.springframework.boot:spring-boot-starter-test:jar:1.5.1.RELEASE:test
[WARNING] org.springframework.boot:spring-boot-starter-actuator:jar:1.5.1.RELEASE:compile
Run Code Online (Sandbox Code Playgroud)
我的问题是为什么Spring Boot启动器模式的设计方式与底层构建系统的声明方式完全相反.是否有关于该主题的发布讨论,或在任何地方给出解释?
spring dependency-management maven maven-dependency-plugin spring-boot
我想下载除了我自己的依赖项之外的所有东西,我还没有编译。我想我需要的是excludeGroupIds,但是如何在命令行上的https://maven.apache.org/plugins/maven-dependency-plugin/go-offline-mojo.html 中设置它或其他任何内容?
我试过这个
mvn dependency:go-offline -DexcludeGroupIds=com.example
Run Code Online (Sandbox Code Playgroud)
我也尝试将它们设置在pom.xmland 中settings.xml,但无法使它们产生任何效果。
我想知道:有没有办法使用Maven Dependency插件(或命令行上的其他东西),列出来自存储库(即不在我的pom.xml)中的工件的传递依赖性?
我知道可以mvn dependency:tree用来列出我的本地项目的依赖项,但是我想在将它添加到我的项目之前知道某些东西的依赖关系(即做出明智的决定),并且pom.xml为了依赖的目的将依赖项添加到本地插件似乎是hackish.
我希望我可以运行如下:
mvn dependency:tree "-DgroupId=net.jawr" "-DartifactId=jawr-core" "-Dversion=3.5"
Run Code Online (Sandbox Code Playgroud)
我提出的最好的是:
~/.m2/repository)mvn dependency:get "-DgroupId=net.jawr" "-DartifactId=jawr-core" "-Dversion=3.5" 但这似乎非常黑客和浪费.
PS - 我不在乎它是否是树格式.
在Eclipse中,当我转到Maven Dependency Hierarchy页面时,我得到输出,指出导致版本被忽略的冲突:
但是,如果我使用dependency:tree,那就省略了,我只看到实际使用的evrsions:
| +- commons-httpclient:commons-httpclient:jar:3.1:compile
| +- commons-codec:commons-codec:jar:1.4:compile
| +- commons-io:commons-io:jar:2.4:compile
| +- commons-net:commons-net:jar:3.1:compile
| +- javax.servlet:servlet-api:jar:2.5:compile
Run Code Online (Sandbox Code Playgroud)
后来实际引用的版本......
+- commons-collections:commons-collections:jar:3.1:compile
Run Code Online (Sandbox Code Playgroud)
有没有办法获得依赖:树输出省略冲突的版本?
谢谢!
我有父母pom和两个模块poms.在第一个模块中,我想将第二个模块(jar)复制到某个文件夹.当我从第一个模块pom编译项目时 - 它工作,但当我尝试从父项目pom编译时,插件尝试复制jar的模块类:
[错误]无法执行目标org.apache.maven.plugins:maven-dependency-plugin:2.1:复制(默认)项目模块1:错误将工件从/ home/chardex/projects/test/module2/target/classes复制到/ home/chardex/projects/test/module1/target/lib/classes:/ home/chardex/projects/test/module2/target/classes(是目录) - > [帮助1]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>...</groupId>
<artifactId>module2</artifactId>
<version>...</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
谢谢.
我正在尝试下载tomcat zip artifact并将其解压缩到一个名为tomcat的文件夹中.我得到的是tomcat/apache-tomcat-7.0.19 /如何摆脱恼人的中间目录?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>unpack-tomcat</id>
<phase>process-sources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.apache</groupId>
<artifactId>tomcat</artifactId>
<version>7.0.19-win64</version>
<type>zip</type>
<overWrite>false</overWrite>
<outputDirectory>tomcat</outputDirectory>
<excludes>webapps/**</excludes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud) mvn dependency-tree"+"和"\"之间输出的区别是什么.对我来说这似乎相当武断,但我确信它不是......
+- com.tom:artifact:pom:6.0.0:compile
| +- com.tom:artifact2:jar:1.0.4:compile
| \- com.tom:artifact3:jar:6.0.0:compile
| \- (com.tom:artifact4:jar:1.0.4:compile - omitted for duplicate)
Run Code Online (Sandbox Code Playgroud)
[我显然删除了实际的组/工件ID ...]
我的根本问题是,当我为控制器和Freemarker视图运行基于"spring-test"的测试时,我需要在WEB-INF/lib文件夹中包含所有taglib - 否则freemarker将无法在测试期间找到它们.我使用以下maven配置解决了这个问题.它实际上在运行测试之前将taglibs jar复制到src/main/webapp/WEB-INF/lib文件夹.我不想清除此文件夹,因为在为IDE运行此测试时问题是相同的.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.3</version>
<executions>
<!-- Freemaarker requires that all taglibs should reside in WEB-INF/lib folder -->
<execution>
<id>tests</id>
<phase>test-compile</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/src/main/webapp/WEB-INF/lib/</outputDirectory>
<artifactItems>
<artifactItem>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>${spring.security.version}</version>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
现在我正在将我的项目迁移到gradle.如何用gradle实现同样的目标?
maven ×10
maven-2 ×2
maven-plugin ×2
dependencies ×1
eclipse ×1
gradle ×1
java ×1
m2eclipse ×1
pom.xml ×1
spring ×1
spring-boot ×1
tomcat ×1
unpack ×1