我是新手。我想设置一个具有以下属性的多模块项目环境:
war.dependsOn
部分)project(':webapp-server').projectDir = new File('../webapp-server')
代码的原因:settings.gradle)我做了以下结构:
以下是这些文件的来源: webapp:build.gradle:
apply plugin: 'java'
apply plugin: 'war'
sourceCompatibility = theSourceCompatibility
group = theProjectGroup
version = theProjectVersion
repositories {
maven {
url "${artifactoryContextUrl}/remote-repos"
}
}
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.1.1"
}
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
}
war.dependsOn(":webapp-client:gruntBuild")
war.dependsOn(":webapp-server:explodedWar")
war {
from "../webapp-client/dist"
from { project(":webapp-server").explodedWar }
}
apply plugin: "com.jfrog.artifactory"
apply plugin: 'maven-publish'
artifactory {
contextUrl = "${artifactoryContextUrl}"
publish {
repository {
repoKey = 'libs-release-local'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
defaults {
publications('webApp')
}
}
}
publishing {
publications {
webApp(MavenPublication) {
from components.web
}
}
}
webapp:settings.gradle:
rootProject.name = theProjectName
include ':webapp-server'
project(':webapp-server').projectDir = new File('../webapp-server')
include ':webapp-client'
project(':webapp-client').projectDir = new File('../webapp-client')
webapp:gradle.properties:
theProjectGroup=com.ourcompany
theProjectName=webapp
theProjectVersion=1.0
theSourceCompatibility=1.8
artifactoryContextUrl=http://192.168.0.12:7078/artifactory
artifactory_user=admin
artifactory_password=password
webapp-client:build.gradle:
apply plugin: 'java'
group = theProjectGroup
version = theProjectVersion
repositories {
maven {
url "${artifactoryContextUrl}/remote-repos"
}
}
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'com.moowork.gradle:gradle-node-plugin:0.11'
classpath 'com.moowork.gradle:gradle-grunt-plugin:0.11'
}
}
apply plugin: 'com.moowork.node'
apply plugin: 'com.moowork.grunt'
node {
version = '4.2.6'
npmVersion = '3.7.1'
download = true
}
task npmCacheConfig(type: NpmTask) {
description = "Configure the NPM cache"
def npmCacheDir = "${gradle.getGradleUserHomeDir()}/caches/npm"
outputs.files file(npmCacheDir)
args = ['config', 'set', 'cache', npmCacheDir]
}
task npmPackages(type: NpmTask, dependsOn: npmCacheConfig) {
description = "Install Node.js packages"
args = ['install']
inputs.files file('package.json')
outputs.files file('node_modules')
}
task bowerInstall(type: NodeTask) {
script = file('node_modules/bower/bin/bower')
args = ["--config.storage.cache=${gradle.getGradleUserHomeDir()}/caches/bower/cache",
"--config.storage.packages=${gradle.getGradleUserHomeDir()}/caches/bower/packages",
"--config.storage.registry=${gradle.getGradleUserHomeDir()}/caches/bower/registry",
'install']
inputs.files file('bower.json')
outputs.files file('bower_components')
dependsOn npmPackages
}
grunt_build.inputs.dir file('app')
grunt_build.dependsOn 'installGrunt'
grunt_build.dependsOn 'bowerInstall'
task gruntBuild() {
dependsOn grunt_build
}
task gruntServe() {
dependsOn grunt_serve
}
webapp-client:gradle.properties:
theProjectGroup=com.ourcompany
theProjectName=webapp-client
theProjectVersion=1.0-SNAPSHOT
artifactoryContextUrl=http://192.168.0.12:7078/artifactory
artifactory_user=admin
artifactory_password=password
webapp-server:build.gradle:
apply plugin: 'java'
apply plugin: 'war'
group = theProjectGroup
version = theProjectVersion
sourceCompatibility = theSourceCompatibility
repositories {
maven {
url "${artifactoryContextUrl}/libs-snapshot"
}
maven {
url "${artifactoryContextUrl}/remote-repos"
}
}
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.1.1"
}
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
}
apply plugin: "com.jfrog.artifactory"
apply plugin: 'maven-publish'
artifactory {
contextUrl = "${artifactoryContextUrl}"
publish {
repository {
repoKey = 'libs-snapshot-local'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
defaults {
publications('webApp')
}
}
}
publishing {
publications {
webApp(MavenPublication) {
from components.web
}
}
}
task explodedWar(type: Copy, dependsOn: war) {
def zipFile = project.war.archivePath
def outputDir = file("${buildDir}/unpacked/war")
from zipTree(zipFile)
into outputDir
}
webapp-server:gradle.properties:
theProjectGroup=com.ourcompany
theProjectName=webapp-server
theProjectVersion=1.1-SNAPSHOT
artifactoryContextUrl=http://192.168.0.12:7078/artifactory
artifactory_user=admin
artifactory_password=password
webapp-server,webapp-client:settings.gralde:
rootProject.name = theProjectName
正如我所说,我是gralde的新手,并不知道这项工作有多好。我不知道gradle.properties是否是放置变量的好地方。
同时发布神器也会遇到问题。运行gradle artifactoryPublish --info
结果:
Executing task ':webapp-server:artifactoryPublish' (up-to-date check took 0.0 secs) due to:
Task has not declared any outputs.
:webapp-server:artifactoryPublish (Thread[main,5,main]) completed. Took 0.008 secs.
:artifactoryPublish (Thread[main,5,main]) started.
:artifactoryPublish
Executing task ':artifactoryPublish' (up-to-date check took 0.0 secs) due to:
Task has not declared any outputs.
Deploying artifact: http://192.168.0.12:7078/artifactory/libs-snapshot-local/com/ourcompany/webapp-server/1.1-SNAPSHOT/webapp-server-1.1-SNAPSHOT.war
Deploying artifact: http://192.168.0.12:7078/artifactory/libs-snapshot-local/com/ourcompany/webapp-server/1.1-SNAPSHOT/webapp-server-1.1-SNAPSHOT.pom
Deploying artifact: http://192.168.0.12:7078/artifactory/libs-snapshot-local/com/ourcompany/webapp/1.0/webapp-1.0.war
:artifactoryPublish FAILED
:artifactoryPublish (Thread[main,5,main]) completed. Took 1.36 secs.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':artifactoryPublish'.
> java.io.IOException: Failed to deploy file: HTTP response code: 409. HTTP response message: Conflict
似乎在尝试将webapp工件推送到存储库时,一些变量用于'webapp-client'子项目!