简体   繁体   中英

How to copy mutliple jars with gradle?

I want to execute a custom task, which should build some jars and copy these to a different directory.

This is my build.gradle file:

allprojects {
  apply plugin: 'java'
  apply plugin: 'eclipse'
  task hello << { task -> println "I'm project $task.project.name" }
}

subprojects {
  repositories {
    maven {
      url "http://repo1.maven.org/maven2"
    }
  }

  task allDependencies(type: DependencyReportTask) {}
  task allDependenciesInsight(type: DependencyInsightReportTask) << {}

  dependencies {
    compile 'log4j:log4j:1.2.14'
    compile 'org.eclipse.jdt:org.eclipse.jdt.annotation:2.0.+'

    testCompile "junit:junit:4.+"
    testCompile 'org.mockito:mockito-all:1.10.+'
  }

  task copyJars(type: Copy) << {
    println "Copies artifacts from " + project.libsDir + " to " + project.rootDir + "."
    from('$project.libsDir')
    into('$project.rootDir')
  }
}

task bamm(type: Copy) << {
  description "Creates BAMM plugin."
  println "Creates BAMM plugin."
  println "Copies artifacts from " + project.libsDir + " to " + gradle.bammDir
  from(project.libsDir)
  into(gradle.bammDir)
}

bamm.dependsOn ':camm-server:jar', ':camm-server:copyJars'

project(':camm-shared') {
  dependencies {
    compile 'joda-time:joda-time:1.5.2'
    compile 'org.springframework:spring:2.5.6.+'
    compile files ('../lib/MarketInterface.jar')
  }
}

project(':camm-client') {
  dependencies {
    compile 'org.jfree:jfreechart:1.0.+'
    compile project(':camm-shared')
  }
}

project(':camm-server') {
  dependencies {
    compile 'org.jibx:jibx-run:1.2.+'
    compile project(':camm-client')
    compile project(':camm-shared')

    testCompile files ('../lib/MarketInterface.jar')
    testCompile project(':camm-shared').sourceSets.test.output
  }
}

task wrapper(type: Wrapper) {
  gradleVersion = '2.8'
}

I can run the bamm task but it never copies anything.

My goal is to build all necessary jars (which works) and to copy all of the jars created from my projects to the gradle.bammDir .

from and into does not work when added in an action ( << ). It should be:

task bamm(type: Copy) {
  description "Creates BAMM plugin."
  println "Creates BAMM plugin."
  println "Copies artifacts from " + project.libsDir + " to " + gradle.bammDir
  from(project.libsDir)
  into(gradle.bammDir)
}

or:

task bamm << {
  description "Creates BAMM plugin."
  println "Creates BAMM plugin."
  println "Copies artifacts from " + project.libsDir + " to " + gradle.bammDir
  copy {
     from(project.libsDir)
     into(gradle.bammDir)
  }
}

Please read about configuration and execution phase - it's crucial to understand how gradle works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM