首先,写一个maven parent
<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.lala</groupId> <artifactId>my-parent</artifactId> <version>0.0.1</version> <packaging>pom</packaging> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.4.0</version> <scope>provided</scope> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>javax.mail</groupId> <artifactId>javax.mail-api</artifactId> <version>1.5.3</version> <scope>provided</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.3</version> <configuration> <source>1.8</source> <target>1.8</target> <verbose>true</verbose> </configuration> </plugin> </plugins> </build> </project>
dependencies里面的依赖是:2.4.0的jedis
dependencyManagement里面的依赖是:1.5.3的java.mail
子模块这样写的话
<parent> <groupId>com.lala</groupId> <artifactId>my-parent</artifactId> <version>0.0.1</version> </parent>
会有如下反应:
1:子模块会自动引入父模块的dependencies依赖,而不会自动引入dependencyManagement的依赖
2:dependencyManagement里只是声明依赖,并不实现引入,因此子项目需要显式的声明需要用的依赖,而且不需要指定version、scope,系统会自动用父模块的version、scope
maven技术交流 扣扣群 379165311,群里面会不定期分享一些maven文章和教程,欢迎大家加入
时间: 2024-11-05 17:29:56