Java plugin should add artifacts to an artifacts configuration


(David Kowis) #1

Unless I understand the documentation incorrectly ( http://www.gradle.org/docs/current/userguide/userguide_single.html#sec:java_plugin_and_dependency_management ), the java plugin should automatically add an assembled jar to the archives configuration, and so then I should be able to reference it in an extended configuration like so:

configurations {
  cucumberRuntime {
    extendsFrom archives, testRuntime
  }
 }

However, this does not include any of the packaged artifacts, only the testRuntime class path, so either I’m doing it completely wrong, or something is broken.

Context: I’m trying to run an ant task against the built artifacts using cucumber-jvm, as an integration test Complete build.gradle file:

apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'idea'
  //build stuff
sourceCompatibility=1.6
targetCompatibility=1.6
  /*task myJar(type: Jar)
  artifacts {
  archives myJar
}*/
  configurations {
  cucumberRuntime {
    extendsFrom archives, testRuntime
  }
 }
  task cucumber {
  dependsOn assemble
    doLast {
    ant.java(
      fork: true,
      classname: "cucumber.cli.Main",
      classpath: configurations.cucumberRuntime.asPath,
      failOnError: true
      ) {
      arg value:"-f"
      arg value:"pretty"
      arg value:"--glue"
      arg value:"src/test/groovy"
      arg value:"src/test/resources"
    }
  }
}
dependencies {
  // Groovy library for groovy building!
  groovy 'org.codehaus.groovy:groovy-all:2.0.0-beta-2'
    testCompile 'junit:junit:4.10'
  testCompile 'info.cukes:cucumber-junit:1.0.0.RC15'
  testCompile 'info.cukes:cucumber-groovy:1.0.0.RC15'
}
  repositories {
  mavenCentral()
}

(David Kowis) #2

so I found this: http://issues.gradle.org/browse/GRADLE-732

But I cannot find anything in the documentation about how to add a file to a configuration, so that I can reference it as a classpath. How do I work around that in this instance?


(David Kowis) #3

I’ve eventually figured out a workaround for it and my project is here: https://github.com/dkowis/cucumber-jvm-groovy-example

It took me probably about an hour to figure out a workaround to this, and that’s somewhat disappointing


(Peter Niederwieser) #4

It’s not a bug, it’s how things currently work (and how they work in Ivy). A better solution is to set the class path to ‘sourceSets.test.runtimeClasspath.asPath’. That’s how the ‘test’ task brought in by the ‘java’ plugin is being configured.