Unexpected errors on compiling the integration tests


(Jeevak Kasarkod) #1

Im a newbie to Gradle. Im attempting to compile the integration tests using a classpath that is used by the main compile task. The errors I receive are indicative of the fact that the compile classpath is not being set correctly, any advice? Here is my gradle file

apply plugin: ‘java’ apply plugin: ‘eclipse’

sourceCompatibility = 1.7 version = rootProject.version jar {

manifest {

attributes ‘Implementation-Title’: rootProject.modname, ‘Implementation-Version’: rootProject.version

} }

repositories {

mavenCentral()

ivy {

// URL can refer to a local directory

url “local-repo”

} }

configurations{

integTest.extendsFrom testCompile }

sourceSets{

integTest{

java.srcDir file(‘src/integration-tests/java’)

compileClasspath= sourceSets.main.output + sourceSets.test.output + configurations.integTest

} }

dependencies {

compile group: ‘javax.activation’, name: ‘activation’, version: ‘1.1’

compile group: ‘axis’, name: ‘axis’, version: ‘1.4’

//compile group: ‘commons-collections’, name: ‘commons-collections’, version: ‘3.2’

compile group: ‘commons-discovery’, name: ‘commons-discovery’, version: ‘0.2’

compile group: ‘commons-logging’, name: ‘commons-logging’, version: ‘1.0.2’

compile group: ‘axis’, name: ‘axis-jaxrpc’, version: ‘1.4’

compile group: ‘log4j’, name: ‘log4j’, version: ‘1.2.16’

compile group: ‘javax.mail’, name: ‘mail’, version: ‘1.4’

compile group: ‘axis’, name: ‘axis-wsdl4j’, version: ‘1.5.1’

compile group: ‘javax.servlet’, name: ‘javax.servlet-api’, version: ‘3.1.0’

compile group: ‘commons-fileupload’, name: ‘commons-fileupload’, version:‘1.3’

compile fileTree(dir: ‘local-repo’, include: ‘*.jar’)

testCompile group: ‘junit’, name: ‘junit’, version: ‘4.11’ }

test { }

uploadArchives {

repositories {

flatDir {

dirs ‘repos’

}

} }


(Peter Niederwieser) #2

We’d need more information, such as what exactly the error (message) is, what exactly you mean by “not correctly”, etc. One thing that’s missing is a ‘runtimeClasspath’ for the new source set. I recommend to check out the ‘java/withIntegrationTests’ sample in the full Gradle distribution.

PS: Please wrap code snippets in HTML code tags.


(Jeevak Kasarkod) #3

It was a runtime config error which I discovered after posting the question, the config files were being copied to an incorrect location. How do I set the runtime classpath for a java exec task to also include the compile classpath for the main sourceSet?

I get a

* What went wrong:
A problem occurred evaluating root project 'FileTokenizerGradle'.
> You can't change a configuration which is not in unresolved state!

for a javaexec task that contains

classpath= sourceSets.main.runtimeClasspath + sourceSets.main.compileClasspath

(Peter Niederwieser) #4

‘runtimeClasspath’ will typically already include ‘compileClasspath’. If you get “can’t change a configuration which is not in unresolved state” here, then some part of the build script is resolving the configuration too early (in the configuration phase).


(Jeevak Kasarkod) #5

If I assign only the runtimeClasspath to the classpath in my Java exec task it does not use the compileClasspath. Here are the relevant gradle files

build.gradle:

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'application'
apply from: 'gradle/integration-test.gradle'
apply from: 'gradle/run.gradle'
apply from: 'gradle/init.gradle'
  applicationName= "Filetokenizer"
mainClassName= "com.services.processor.fileMonitor"
  sourceCompatibility = 1.7
version = rootProject.version
jar {
    manifest {
        attributes 'Implementation-Title': rootProject.modname, 'Implementation-Version': rootProject.version
    }
}
  repositories {
    mavenCentral()
 ivy {
  // URL can refer to a local directory
  url "local-repo"
 }
}
  dependencies {
 compile group: 'javax.activation', name: 'activation', version: '1.1'
 compile group: 'axis', name: 'axis', version: '1.4'
 compile group: 'commons-discovery', name: 'commons-discovery', version: '0.2'
 compile group: 'commons-logging', name: 'commons-logging', version: '1.0.2'
 compile group: 'axis', name: 'axis-jaxrpc', version: '1.4'
 compile group: 'log4j', name: 'log4j', version: '1.2.16'
 compile group: 'javax.mail', name: 'mail', version: '1.4'
 compile group: 'axis', name: 'axis-wsdl4j', version: '1.5.1'
 compile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
 compile group: 'commons-fileupload', name: 'commons-fileupload', version:'1.3'
 compile fileTree(dir: 'local-repo', include: '*.jar')
 testCompile group: 'junit', name: 'junit', version: '4.11'
}
test {
}

run.gradle:

task copyConfigFiles(type:Copy){
 from 'src/main/resources'
 exclude '**/*.csv'
 into 'build/classes/main/conf'
 logDir=new File("logs")
 logDir.mkdirs()
}
  task runJava(type: JavaExec){
 dependsOn classes
 File log4jFile = file('build/classes/main/conf/log4j.properties')
 log4jFile = file(log4jFile.absolutePath)
 description = 'Run voltage file monitor for tokenization'
 // Java main class to execute.
 main = 'com.services.processor.fileMonitor'
 // We need to set the classpath.
 classpath= sourceSets.main.runtimeClasspath
 println classpath
 // Extra options can be set.
 maxHeapSize='256m'
 jvmArgs '-Dlog4j.configuration='+ log4jFile + ' -Djava.library.path=\"' + rootProject.DllLocation + '\" -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9999 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=localhost'
 // We can pass arguments to the main() method
 // of gradle.sample.SampleApp.
 args 'build/classes/main/conf/config.xml'
 println commandLine
}
runJava.dependsOn copyConfigFiles
  task copySampleFiles(type: Copy){
 dependsOn runJava
 from 'src/main/resources'
 include '**/*.csv'
 into 'monitor/inputfiles'
}
  task validateInstallation{ dependsOn copySampleFiles }

(Jeevak Kasarkod) #6

Paste error, here is the actual run.gradle:

task copyConfigFiles(type:Copy){
 from 'src/main/resources'
 exclude '**/*.csv'
 into 'build/classes/main/conf'
 logDir=new File("logs")
 logDir.mkdirs()
}
  task runJava(type: JavaExec){
 dependsOn classes
 File log4jFile = file('build/classes/main/conf/log4j.properties')
 log4jFile = file(log4jFile.absolutePath)
 description = 'Run voltage file monitor for tokenization'
 // Java main class to execute.
 main = 'com.voltage.services.processor.file.FilesystemMonitor'
 // We need to set the classpath.
 classpath= sourceSets.main.runtimeClasspath
 println classpath
 // Extra options can be set.
 maxHeapSize='256m'
 jvmArgs '-Dlog4j.configuration='+ log4jFile + ' -Djava.library.path=\"' + rootProject.DllLocation + '\" -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9999 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=localhost'
 // We can pass arguments to the main() method
 // of gradle.sample.SampleApp.
 args 'build/classes/main/conf/config.xml'
 println commandLine
}
runJava.dependsOn copyConfigFiles
  task copySampleFiles(type: Copy){
 dependsOn runJava
 from 'src/main/resources'
 include '**/*.csv'
 into 'monitor/inputfiles'
}
  task validateInstallation{ dependsOn copySampleFiles }

(Peter Niederwieser) #7

Try the following:

task printCompileClasspath << {
    sourceSets.main.compileClasspath.each { println it }
}
task printRuntimeClasspath << {
    sourceSets.main.runtimeClasspath.each { println it }
}

(Jeevak Kasarkod) #8
:printCompileClasspath
C:\Hadoop\workspace\FileTokenizerGradle\local-repo\commons-collections4-4.0-alpha1.jar
C:\Hadoop\workspace\FileTokenizerGradle\local-repo\vibesimplejava.jar
C:\Hadoop\workspace\FileTokenizerGradle\local-repo\vibews.jar
C:\Hadoop\workspace\FileTokenizerGradle\local-repo\vssoaclient_v55.jar
C:\Users\jeevak\.gradle\caches\artifacts-23\filestore\javax.activation\activation.1\jar\e6cb541461c2834bdea3eb920f1884d1eb508b50\activation-1.1.jar
C:\Users\jeevak\.gradle\caches\artifacts-23\filestore\axis\axis.4\jar4a9ce681a42d0352b3ad22659f67835e560d107\axis-1.4.jar
C:\Users\jeevak\.gradle\caches\artifacts-23\filestore\commons-discovery\commons-discoverye51ad56d2953726c6a1233ab1c838f53.2\jar773ac7a7248f08ed2b8d297c6e2ef28260640ea\commons-discovery-0.2.jar
C:\Users\jeevak\.gradle\caches\artifacts-23\filestore\log4j\log4j.2.16\bundle999a63bfccbc7c247a9aea10d83d4272bd492c6\log4j-1.2.16.jar
C:\Users\jeevak\.gradle\caches\artifacts-23\filestore\javax.mail\mail.4\jaraa1579ae5ecd41920c4f355b0a9ef40b68315dd\mail-1.4.jar
C:\Users\jeevak\.gradle\caches\artifacts-23\filestore\axis\axis-wsdl4j.5.1\jar\bd804633b9c2cf06258641febc31a8ff3b0906bc\axis-wsdl4j-1.5.1.jar
C:\Users\jeevak\.gradle\caches\artifacts-23\filestore\javax.servlet\javax.servlet-api.1.0\jarcd63d075497751784b2fa84be59432f4905bf7c\javax.servlet-api-3.1.0.jar
C:\Users\jeevak\.gradle\caches\artifacts-23\filestore\commons-fileupload\commons-fileupload.3\jar\c89e540e4a12cb034fb973e12135839b5de9a87e\commons-fileupload-1.3.jar
C:\Users\jeevak\.gradle\caches\artifacts-23\filestore\commons-logging\commons-logging.0.4\jar\f029a2aefe2b3e1517573c580f948caac31b1056\commons-logging-1.0.4.jar
C:\Users\jeevak\.gradle\caches\artifacts-23\filestore\org.apache.axis\axis-jaxrpc.4\jar\b393f1f0c0d95b68c86d0b1ab2e687bb71f3c075\axis-jaxrpc-1.4.jar
C:\Users\jeevak\.gradle\caches\artifacts-23\filestore\org.apache.axis\axis-saaj.4\jar81149d1f391258754354f2acf2b56665d53de2e\axis-saaj-1.4.jar
C:\Users\jeevak\.gradle\caches\artifacts-23\filestore\commons-io\commons-io.2\jar3b5b8a7ba1c08f9e8c8ff2373724e33d3c1e22a\commons-io-2.2.jar
.
:printRuntimeClasspath
C:\Hadoop\workspace\FileTokenizerGradle\build\classes\main
C:\Hadoop\workspace\FileTokenizerGradle\build\resources\main

(Jeevak Kasarkod) #9

Compile Classpath:

:printCompileClasspath
C:\Hadoop\workspace\FileTokenizerGradle\local-repo\commons-collections4-4.0-alpha1.jar
C:\Hadoop\workspace\FileTokenizerGradle\local-repo\vibesimplejava.jar
C:\Hadoop\workspace\FileTokenizerGradle\local-repo\vibews.jar
C:\Hadoop\workspace\FileTokenizerGradle\local-repo\vssoaclient_v55.jar
C:\Users\jeevak\.gradle\caches\artifacts-23\filestore\javax.activation\activation.1\jar\e6cb541461c2834bdea3eb920f1884d1eb508b50\activation-1.1.jar
C:\Users\jeevak\.gradle\caches\artifacts-23\filestore\axis\axis.4\jar4a9ce681a42d0352b3ad22659f67835e560d107\axis-1.4.jar
C:\Users\jeevak\.gradle\caches\artifacts-23\filestore\commons-discovery\commons-discovery60708d031261b7fd07b445490d5ca97d.2\jar773ac7a7248f08ed2b8d297c6e2ef28260640ea\commons-discovery-0.2.jar
C:\Users\jeevak\.gradle\caches\artifacts-23\filestore\log4j\log4j.2.16\bundle999a63bfccbc7c247a9aea10d83d4272bd492c6\log4j-1.2.16.jar
C:\Users\jeevak\.gradle\caches\artifacts-23\filestore\javax.mail\mail.4\jaraa1579ae5ecd41920c4f355b0a9ef40b68315dd\mail-1.4.jar
C:\Users\jeevak\.gradle\caches\artifacts-23\filestore\axis\axis-wsdl4j.5.1\jar\bd804633b9c2cf06258641febc31a8ff3b0906bc\axis-wsdl4j-1.5.1.jar
C:\Users\jeevak\.gradle\caches\artifacts-23\filestore\javax.servlet\javax.servlet-api.1.0\jarcd63d075497751784b2fa84be59432f4905bf7c\javax.servlet-api-3.1.0.jar
C:\Users\jeevak\.gradle\caches\artifacts-23\filestore\commons-fileupload\commons-fileupload.3\jar\c89e540e4a12cb034fb973e12135839b5de9a87e\commons-fileupload-1.3.jar
C:\Users\jeevak\.gradle\caches\artifacts-23\filestore\commons-logging\commons-logging.0.4\jar\f029a2aefe2b3e1517573c580f948caac31b1056\commons-logging-1.0.4.jar
C:\Users\jeevak\.gradle\caches\artifacts-23\filestore\org.apache.axis\axis-jaxrpc.4\jar\b393f1f0c0d95b68c86d0b1ab2e687bb71f3c075\axis-jaxrpc-1.4.jar
C:\Users\jeevak\.gradle\caches\artifacts-23\filestore\org.apache.axis\axis-saaj.4\jar81149d1f391258754354f2acf2b56665d53de2e\axis-saaj-1.4.jar
C:\Users\jeevak\.gradle\caches\artifacts-23\filestore\commons-io\commons-io.2\jar3b5b8a7ba1c08f9e8c8ff2373724e33d3c1e22a\commons-io-2.2.jar

and runtime classpath

:printRuntimeClasspath
C:\Hadoop\workspace\FileTokenizerGradle\build\classes\main
C:\Hadoop\workspace\FileTokenizerGradle\build\resources\main

(Jeevak Kasarkod) #10

The code tags are messing up the output. I will truncate it, hopefully that works:

:printCompileClasspath
C:\Hadoop\workspace\FileTokenizerGradle\local-repo\commons-collections4-4.0-alpha1.jar
C:\Hadoop\workspace\FileTokenizerGradle\local-repo\vibesimplejava.jar
C:\Hadoop\workspace\FileTokenizerGradle\local-repo\vibews.jar
C:\Hadoop\workspace\FileTokenizerGradle\local-repo\vssoaclient_v55.jar

and for runtime

:printRuntimeClasspath
C:\Hadoop\workspace\FileTokenizerGradle\build\classes\main
C:\Hadoop\workspace\FileTokenizerGradle\build\resources\main

(Peter Niederwieser) #11

Looks like the source set’s runtime class path gets reconfigured incorrectly in one of your build scripts. If you try with a vanilla build script, you’ll see that the runtime class path is a superset of the compile class path.


(Jeevak Kasarkod) #12

The runtimeclasspath is affected by the run.gradle file I pasted earlier in this thread. However I do not mess with any source sets in the file. What should I be looking for?


(Peter Niederwieser) #13

It’d try to take things away until the problem no longer exists, than add things back in. ‘println runtimeClasspath’ should be eliminated or wrapped in ‘doFirst {…}’, as otherwise the class path gets resolved at configuration time. Maybe that’s already the problem.