使用子项目

时间:2016-03-08 08:56:24

标签: gradle artifactory multi-project subproject

我是新手。我想设置一个具有以下属性的多模块项目环境:

  1. 主项目名为'webapp',它有两个子项目'webapp-client'和'webapp-server',其中客户端是基于javascript的项目,服务器是RESTFull堆栈。
  2. 'webapp-client'和'webapp-server'中的每一个都应该是独立的项目,即可以像没有'webapp'超级项目那样开发它们。 'webapp-client'在内部使用Node.js,Bower和Grunt,但我尝试将它们集成为gradle任务。
  3. 'webapp-client'将其输出构建到项目的'dist'文件夹中。 'webapp-server'创建一个部署到JFrog Artifactory的war文件。
  4. “webapp”项目创建了另一个工件。它将'webapp-client'和'webapp-server'的输出结合到一个war文件中。它也被部署到Artifactory(参见webapp:build.gradle文件中的war.dependsOn部分)
  5. 每个项目都在一个单独的Git存储库下进行版本控制(这就是在webapp中定义project(':webapp-server').projectDir = new File('../webapp-server')代码的原因:settings.gradle)
  6. 我尝试的是将所有变量重构为gradle.properties文件
  7. 我做了以下结构:

    project structure

    以下是这些文件的来源: 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'子项目!

0 个答案:

没有答案