本地仓库设置、IDEA Maven全局设置
本地仓库设置
目的:将Maven下载的依赖包全部下载到指定的目录下,方便管理。


IDEA Maven 全局设置



提示:全局设置仅还未生成 .idea 目录的项目有效,因此为了让此配置生效,若已有此目录,则请先删除。
依赖版本范围
maven项目中所依赖的jar包版本不是唯一特定的版本,可以使用版本范围设定,设定的规则见下表:
1.0 | x >= 1.0 * The default Maven meaning for 1.0 is everything (,) but with 1.0 recommended. Obviously this doesn’t work for enforcing versions here, so it has been redefined as a minimum version. |
(,1.0] | x <= 1.0 |
(,1.0) | x < 1.0 |
[1.0] | x == 1.0 |
[1.0,) | x >= 1.0 |
(1.0,) | x > 1.0 |
(1.0,2.0) | 1.0 < x < 2.0 |
[1.0,2.0] | 1.0 <= x <= 2.0 |
(,1.0],[1.2,) | x <= 1.0 or x >= 1.2. Multiple sets are comma-separated |
(,1.1),(1.1,) | x != 1.1 |
<dependency> <groupId>com.falsec.nsm</groupId> <artifactId>fal-common</artifactId> <version>[1.4.0,1.5.0)</version> </dependency>
标识依赖版本为大于等于1.4.0,且小于1.5.0的jar包。
FAQ
1 设置第三方依赖包中依赖scope值,由runtime到compile
我们在pom文件中添加 dependency时,如果不设置 scope,那么默认使用的是 compile,例如:
<dependency> <groupId>org.apereo.cas</groupId> <artifactId>cas-server-core-webflow</artifactId> <version>5.2.0</version> </dependency>
这个依赖包中,又包含了 org.apereo.cas:cas-server-core-util:jar:5.2.0:runtime,注意它的scope是 runtime:
mvn dependency:tree ...... ...... +- org.apereo.cas:cas-server-core-webflow:jar:5.2.0:compile [INFO] | +- org.apereo.cas:cas-server-core-api-ticket:jar:5.2.0:compile [INFO] | +- org.apereo.cas:cas-server-core-api:jar:5.2.0:compile [INFO] | | +- org.apereo.cas:cas-server-core-api-logout:jar:5.2.0:compile [INFO] | | \- org.apereo.cas:cas-server-core-api-validation:jar:5.2.0:compile [INFO] | +- org.apereo.cas:cas-server-core-util:jar:5.2.0:runtime [INFO] | | +- org.bitbucket.b_c:jose4j:jar:0.6.1:runtime [INFO] | | +- org.apereo.cas:cas-server-core-api-util:jar:5.2.0:runtime [INFO] | | +- org.apereo.cas:cas-server-core-api-web:jar:5.2.0:runtime [INFO] | | +- org.apache.shiro:shiro-core:jar:1.4.0:runtime [INFO] | | | +- org.apache.shiro:shiro-lang:jar:1.4.0:runtime [INFO] | | | +- org.apache.shiro:shiro-cache:jar:1.4.0:runtime [INFO] | | | +- org.apache.shiro:shiro-crypto-hash:jar:1.4.0:runtime [INFO] | | | | \- org.apache.shiro:shiro-crypto-core:jar:1.4.0:runtime [INFO] | | | +- org.apache.shiro:shiro-crypto-cipher:jar:1.4.0:runtime [INFO] | | | +- org.apache.shiro:shiro-config-core:jar:1.4.0:runtime [INFO] | | | +- org.apache.shiro:shiro-config-ogdl:jar:1.4.0:runtime [INFO] | | | \- org.apache.shiro:shiro-event:jar:1.4.0:runtime [INFO] | | +- com.google.zxing:core:jar:3.3.0:runtime [INFO] | | \- com.vdurmont:semver4j:jar:2.0.3:runtime ...... ......
同事直接使用它来在项目中写代码,提交后,导致我这边一片红:
解决方法很简单,将这个 runtime 改为 compile 就可以了: