Maven的SNAPSHOT不自动更新
需要配置setting.xml中的profile,配置为实时更新快照版本
<profiles>
<profile>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>libs-release</name>
<url>http://xxx.com:80/artifactory/libs-release</url>
</repository>
<repository>
<!-- <snapshots/> -->
<!! 重点要配置这个,才会实时检查并且更新快照版本>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
<id>snapshots</id>
<name>libs-snapshot</name>
<url>http://xxx.com:80/artifactory/libs-snapshot</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>plugins-release</name>
<url>http://xxx.xxx.com:80/artifactory/plugins-release</url>
</pluginRepository>
<pluginRepository>
<!-- <snapshots/> -->
<!! 重点要配置这个,才会实时检查并且更新快照版本的插件>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
<id>snapshots</id>
<name>plugins-snapshot</name>
<url>http://xxx.com:80/artifactory/plugins-snapshot</url>
</pluginRepository>
</pluginRepositories>
<id>artifactory</id>
</profile>
</profiles>
Gradle的SNAPSHOT不自动更新
需要两步配置
- 设置仓库为私服,不要使用mavenLocal(),使用mavenLocal()就会如果maven本地仓库存在则会使用maven本地仓库,否则才会使用gradle的cache
- 配置更新策略为实时更新
注:gradle缓存的依赖在,/Users/xxx/gradle-4.10.3/caches/modules-2/files-2.1(gradle安装目录),可以通过idea的Project Structure-->Libraries来查看依赖jar包的本地位置
// 所有工程的共用,一般不需要修改
allprojects {
apply plugin: 'java'
apply plugin: 'maven'
version = '1.0-SNAPSHOT'
sourceCompatibility = 1.8
targetCompatibility = 1.8
// 仓库地址 !!不配置mavenLocal()
repositories {
maven { url 'http://xxx.com/nexus/content/groups/public/' }
maven { url 'http://repo.spring.io/milestone' }
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
testCompile 'org.mockito:mockito-core:1.10.19'
testCompile 'org.powermock:powermock-api-mockito:1.6.2'
testCompile 'org.powermock:powermock-module-junit4:1.6.2'
compile 'org.projectlombok:lombok:1.16.18'
// gradle 4.8 need
annotationProcessor('org.projectlombok:lombok:1.16.18')
}
}
// 所有子模块的任务, 定义私服的上传地址
subprojects {
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives sourcesJar
}
// 定义检查依赖变化的时间间隔,!!配置为0实时刷新
configurations.all {
// check for updates every build
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
processResources {
from('src/main/java') {
include '**/*'
}
}
uploadArchives {
repositories {
mavenDeployer {
if (project.version.endsWith('-SNAPSHOT')) {
repository(url: "http://xxx.com/nexus/content/repositories/snapshots/") {
authentication(userName: "xxx", password: "xxx")
}
} else {
repository(url: "http://xxx.com/nexus/content/repositories/releases/") {
authentication(userName: "xxx", password: "xxx")
}
}
}
}
}
}