No persistent classes found when integration test in Gradle - spring

My project bases on Spring+JPA+Hibernate, and use Ant to manage build process before, now I am intending to use Gradle. While when run 'gradle clean test', I got a exception as below:
[2013-02-07 11:01:36,703][Test worker][WARN ][QuerySplitter] no persistent classes found for query class: from com.mpos.lottery.te.workingkey.domain.WorkingKey w where w.createDateStr=:createDateStr and w.gpeId=:gpeId
[2013-02-07 11:01:36,718][Test worker][ERROR][TEPortServlet] org.hibernate.QueryParameterException: could not locate named parameter [gpeId]; nested exception is java.lang.IllegalArgumentException: org.hibernate.QueryParameterException: could not locate named parameter [gpeId]
I have ran that test case(doesn't need jetty) in both eclipse and Ant, it passed, So i suspect that some incorrect configuration in gradle cause this exception.
Below is my gradle script:
apply plugin: 'war'
// 'war' plugin will apply 'java' plugin automatically
apply plugin: 'java'
apply plugin: 'eclipse'
// run web application, refer to http://gradle.org/docs/current/userguide/jetty_plugin.html
apply plugin: 'jetty'
compileJava.options.encoding = _sourcecode_encoding
compileTestJava.options.encoding = _sourcecode_encoding
// Properties added by the java plugin
sourceCompatibility="${_source_compatibility}"
targetCompatibility="${_target_compatibility}"
//Properties added by the 'war' plugin
webAppDirName="src/main/WWW"
configurations {
provided {
description = 'Non-exported comiple-time dependencies, it will be provided by container.'
}
}
dependencies {
provided files('lib/DEV/j2ee/servlet-api.jar')
compile fileTree(dir: 'lib', include: '**/*.jar', exclude: 'DEV/**/*.jar')
//compile sourceSets.main.output
testCompile fileTree(dir:"lib", include:"DEV/**/*.jar")
}
sourceSets {
main {
compileClasspath = compileClasspath + configurations.provided
//compileClasspath.collect().each({println it})
resources {
srcDir 'src/main/resource'
}
}
test {
resources {
srcDir 'src/test/resource'
}
}
}
test {
scanForTestClasses = false
classpath = configurations.provided + configurations.compile + configurations.testCompile + sourceSets.main.output + sourceSets.test.output
classpath.each({println it})
// customize test process
include 'com/mpos/lottery/te/gameimpl/smsraffle/**/*Test.class'
}
I am new learner of Gradle and groovy, pls help me. Thanks in advance.

By default, Gradle uses separate output directories for classes and resources, which can cause problems with Hibernate/JPA. Try:
sourceSets.main.output.resourcesDir = sourceSets.main.output.classesDir
sourceSets.test.output.resourcesDir = sourceSets.test.output.classesDir
You might not need the latter.

Related

Error using Gradle Vaadin Plugin

I am trying to add Gradle Vaadin Plugin to my project, but I get the below error.
Errors in 'jar:file:/C:/Users/DEMO/.gradle/caches/modules-2/files-2.1/com.google.gwt/gwt-user/2.8.1/9a13fbee70848f1f1cddd3ae33ad180af3392d9e/gwt-user-2.8.1.jar!/com/google/gwt/vali
dation/client/impl/GwtValidatorContext.java'
Line 29: The type GwtValidatorContext must implement the inherited abstract method ValidatorContext.parameterNameProvider(ParameterNameProvider)
Tracing compile failure path for type 'com.vaadin.client.communication.AtmospherePushConnection'
Errors in 'jar:file:/C:/Users/DEMO/.m2/repository/com/vaadin/vaadin-client/8.0.6/vaadin-client-8.0.6.jar!/com/vaadin/client/communication/AtmospherePushConnection.java'
Line 212: PUSH_ID_PARAMETER cannot be resolved or is not a field
Tracing compile failure path for type 'javax.validation.executable.ExecutableValidator'
Errors in 'jar:file:/C:/Users/DEMO/.gradle/caches/modules-2/files-2.1/javax.validation/validation-api/1.1.0.Final/7d49b53caed9bd81d172807c3e096d24f3c57090/validation-api-1.1.0.Fina
l-sources.jar!/javax/validation/executable/ExecutableValidator.java'
Line 53: No source code is available for type java.lang.reflect.Method; did you forget to inherit a required module?
Line 94: No source code is available for type java.lang.reflect.Constructor<T>; did you forget to inherit a required module?
Tracing compile failure path for type 'com.vaadin.client.communication.MessageHandler'
Errors in 'jar:file:/C:/Users/DEMO/.m2/repository/com/vaadin/vaadin-client/8.0.6/vaadin-client-8.0.6.jar!/com/vaadin/client/communication/MessageHandler.java'
Line 358: UIDL_PUSH_ID cannot be resolved or is not a field
Line 359: UIDL_PUSH_ID cannot be resolved or is not a field
Tracing compile failure path for type 'com.google.gwt.validation.client.impl.PropertyDescriptorImpl'
Errors in 'jar:file:/C:/Users/DEMO/.gradle/caches/modules-2/files-2.1/com.google.gwt/gwt-user/2.8.1/9a13fbee70848f1f1cddd3ae33ad180af3392d9e/gwt-user-2.8.1.jar!/com/google/gwt/vali
dation/client/impl/PropertyDescriptorImpl.java'
Line 31: The type PropertyDescriptorImpl must implement the inherited abstract method CascadableDescriptor.getGroupConversions()
Errors in 'jar:file:/C:/Users/DEMO/.gradle/caches/modules-2/files-2.1/com.google.gwt/gwt-user/2.8.1/9a13fbee70848f1f1cddd3ae33ad180af3392d9e/gwt-user-2.8.1.jar!/com/google/gwt/vali
dation/client/impl/ConstraintDescriptorImpl.java'
Line 35: The type ConstraintDescriptorImpl<T> must implement the inherited abstract method ConstraintDescriptor<T>.getMessageTemplate()
Line 35: The type ConstraintDescriptorImpl<T> must implement the inherited abstract method ConstraintDescriptor<T>.getValidationAppliesTo()
Tracing compile failure path for type 'com.google.gwt.validation.client.impl.GwtBeanDescriptorImpl'
Here is the page for the plugin: https://github.com/johndevs/gradle-vaadin-plugin/wiki
And, here is my build.gradle file:
buildscript {
ext {
springBootVersion = '1.5.3.RELEASE'
}
repositories {
mavenCentral()
maven {
url "http://maven.vaadin.com/vaadin-addons"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
plugins {
id 'com.devsoap.plugin.vaadin' version '1.2.1'
id 'org.springframework.boot' version '1.5.3.RELEASE'
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'jacoco'
apply plugin: 'application'
jar {
baseName = 'testapp'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
repositories {
mavenCentral()
flatDir {
dirs 'libs'
}
maven {
url "http://maven.vaadin.com/vaadin-addons"
}
}
sourceSets {
main {
output.resourcesDir = "build/classes/main"
}
uiTest {
java.srcDirs=['src/ui-test/java','src/main/java']
resources.srcDir 'src/ui-test/resources'
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-jersey')
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.restdocs:spring-restdocs-mockmvc')
// Spring Boot Security
compile("org.springframework.boot:spring-boot-starter-security")
compile("org.springframework.security.oauth:spring-security-oauth2")
compile('org.springframework.security:spring-security-ldap')
// Spring Actuator
compile("org.springframework.boot:spring-boot-starter-actuator")
// Spring Boot JDBC Starter
compile("org.springframework.boot:spring-boot-starter-jdbc")
// Vaadin
compile('com.vaadin:vaadin-spring-boot-starter')
compile('com.vaadin:vaadin-push')
// Vaadin add-ons
compile("org.vaadin.spring.addons:vaadin-spring-addon-eventbus:2.0.0.RELEASE")
//Vaadin extentions
compile("org.vaadin.spring.extensions:vaadin-spring-ext-security:2.0.0.RELEASE")
// Lombok
compile("org.projectlombok:lombok")
// MyBatis
compile("org.mybatis:mybatis-spring:1.2.3")
compile("org.mybatis:mybatis:3.3.0")
// BoneCP - Connection Pooling
compile("com.jolbox:bonecp:0.8.0.RELEASE")
// PostgreSQL
compile("org.postgresql:postgresql:9.4-1204-jdbc42")
//Vaadin Testbench
uiTestCompile("com.vaadin:vaadin-testbench:5.0.0")
//TypeAhead widget
compile name: 'typeaheadSearchBox-1.0-SNAPSHOT'
}
// Create a new task called uiTest and set its type to Test.
// Configure the location of the compiled test classes.
// Configure the classpath that is used when our integration tests are run.
configurations {
uiTestCompile.extendsFrom testCompile
uiTestRuntime.extendsFrom testRuntime
}
task uiTest(type: Test) {
testClassesDir = sourceSets.uiTest.output.classesDir
classpath = sourceSets.uiTest.runtimeClasspath
}
dependencyManagement {
imports {
mavenBom "com.vaadin:vaadin-bom:8.0.3"
}
}
jacocoTestReport {
reports {
xml.enabled = true
html.enabled = true
}
}
check.dependsOn jacocoTestReport
springBoot {
// Main class of #SpringBootApplication
mainClass = 'com.sample.test.Application'
}
When I check the gradle dependencies, I see 2 version of the "javax.validation:validation-api".
I believe that is causing the problem, but I could not find a way to force vaadin-client to use "javax.validation:validation-api:1.0.0.GA".
I appreciate if you can help me to correct the build.gradle.
The Gradle Vaadin plugin must see the Springboot plugin to do a proper setup. So you have to first use the Springboot plugin, then afterwards the Vaadin plugin.
The reason for the error you see there is, that the dep for javax.validation 1.1 from Springboot overrides all configurations (also the one used to build the client for Vaadin)
On a side note: you apply the Springboot plugin twice -- once in plugins, once with apply. I'd get rid of the buildscript-block and the apply. Then swap the items in plugins.

multiple testng test listeners running using gradle test command

I have 2 custom listeners implementing ITestListener, ISuiteListener, IInvokedMethodListener . when I run the command from gradle as gradle clean --test testname . it runs both listeners though I have only one class defined in the #Listeners annotation in test. Its a gradle project but when I run the test in intellij as testng test it runs with only 1 listener as expected. Can you please tell how to make it run with only 1 listener using gradle command
my build.gradle below and testng version I am using is 6.9.4 and I tried 6.9.10 too
ext {
unitTestingMinHeapSize = "512m"
}
// Apply the java plugin to add support for Java
apply plugin: 'java'
// Apply the application plugin to add support for building an application
apply plugin: 'application'
// Apply the eclipse plugin to add support for building on eclipse
apply plugin: 'eclipse'
// Apply the idea plugin to add support for building on IDEA
apply plugin: 'idea'
// In this section you declare where to find the dependencies of your project
repositories {
// Use 'jcenter' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
mavenCentral()
mavenLocal()
}
// In this section you declare the dependencies for your production and test code
dependencies {
compile project(':oos')
testCompile project(':oos')
compile "commons-pool:commons-pool:$apacheCommonsPool1Version"
compile "org.apache.commons:commons-lang3:$apacheCommonsLangVersion"
compile "org.apache.commons:commons-pool2:$apacheCommonsPool2Version"
compile "com.rabbitmq:amqp-client:$rabbitMQClientVersion"
compile "redis.clients:jedis:$jedisVersion"
compile "org.apache.httpcomponents:httpclient:$httpClientVersion"
compile "org.apache.httpcomponents:httpmime:$httpmimeversion"
compile "io.rest-assured:rest-assured:$restAssuredVersion"
compile "org.hamcrest:hamcrest-all:$hamcrestVersion"
compile "org.postgresql:postgresql:$postgresqlversion"
compile "com.googlecode.json-simple:json-simple:1.1.1"
compile "com.codepine.api:testrail-api-java-client:1.0.2"
testCompile "org.mockito:mockito-all:$mockitoVersion"
testCompile "org.springframework:spring-test:$springVersion"
compile ("org.testng:testng:$testngVersion") {
exclude group: "junit", module: "junit"
}
testCompile "org.apache.commons:commons-pool2:$apacheCommonsPool2Version"
}
test {
for (String key : System.getProperties().keySet()) {
systemProperty key, System.properties["$key"]
}
jvmArgs "-XX:-UseSplitVerifier"
systemProperty "runId", findProperty("runId")
useTestNG { useDefaultListeners = true }
beforeTest { descriptor ->
logger.lifecycle("Running: " + descriptor)
}
minHeapSize = "$unitTestingMinHeapSize"
jvmArgs '-XX:+UseConcMarkSweepGC', '-XX:+CMSIncrementalMode' //,'-XX:+PrintGCDetails','-XX:+PrintGCTimeStamps'
if (System.getProperty("test.profile", "false").equals("true")) {
jvmArgs "-noverify", "-agentpath:${profilerDir}/lib/deployed/jdk16/mac/libprofilerinterface.jnilib=${profilerDir}/lib,5140,0"
}
// listen to standard out and standard error of the test JVM(s)
onOutput { descriptor, event ->
// logger.lifecycle("Test: " + descriptor + " produced standard out/err: " + event.message )
if (event.destination == TestOutputEvent.Destination.StdErr) {
logger.error(" ERROR: " + event.message.trim())
}
}
}

Could not find method cargo() for arguments

I am trying to deploy war to tomcat with gradle cargo,i am getting error could not found method cargo()
C:\Users\naresh.vatsal\workspace_spring_jan14\SpringMvcUsingGradle>gradle build
FAILURE: Build failed with an exception.
Where:
Build file 'C:\Users\naresh.vatsal\workspace_spring_jan14\SpringMvcUsingGradle\build.gradle' line: 45
What went wrong:
A problem occurred evaluating root project 'SpringMvcUsingGradle'.
Could not find method cargo() for arguments [build_3gitu3al50b7kv8zi1ebj3qsr$runclosure3#302aa00f] on root project 'SpringMvcUsingGradle'.
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'war'
apply plugin: 'com.bmuschko.tomcat-base'
apply plugin: 'com.bmuschko.cargo-base'
ext.tomcatVersion = '7.0.67'
sourceCompatibility = 1.7
buildscript {
repositories {
maven {
url "https://plugins.grdev.net/m2/"
}
}
dependencies {
classpath "com.bmuschko:gradle-tomcat-plugin:2.2.4"
classpath 'com.bmuschko:gradle-cargo-plugin:2.2'
}
}
repositories {
mavenCentral()
}
dependencies {
def cargoVersion = '1.4.5'
cargo "org.codehaus.cargo:cargo-core-uberjar:$cargoVersion",
"org.codehaus.cargo:cargo-ant:$cargoVersion"
compile 'org.springframework:spring-context:4.0.0.RELEASE'
compile 'org.springframework:spring-webmvc:4.0.0.RELEASE'
compile 'org.aspectj:aspectjrt:1.7.4'
compile 'javax.inject:javax.inject:1'
compile 'javax.servlet:jstl:1.2'
compile 'org.slf4j:slf4j-api:1.7.5'
compile 'org.slf4j:jcl-over-slf4j:1.7.5'
compile 'org.slf4j:slf4j-log4j12:1.7.5'
compile 'log4j:log4j:1.2.15'
testCompile 'junit:junit:4.7'
}
cargo {
containerId = 'tomcat7x'
port = 8080
local {
homeDir = file('C:/mdi/soft/apache-tomcat-7.0.67')
output = file('C:/mdi/soft/apache-tomcat-7.0.67/output.log')
}
}
war {
version = ''
}
It seems, that you've applied the wrong plugin at the moment. Just change:
apply plugin: 'com.bmuschko.cargo-base'
to
apply plugin: 'com.bmuschko.cargo'
Because, when you apply the com.bmuschko.cargo-base plugin, you have to configure each task individually, according to the plugin description.
And one more, there is no property output, which could be defined within the local closure, but there is an outputFile property, so, your local closure should look like:
local {
homeDir = file('C:/mdi/soft/apache-tomcat-7.0.67')
outputFile = file('C:/mdi/soft/apache-tomcat-7.0.67/output.log')
}

Gradle fails to create Eclipse project files

I am trying to start a new Java EE project with Gradle. I have everything close to the way I want it, and im trying to build the eclipse files. The problem is when i run the command gradle eclipse the eclipse plugin creates the eclipse files for the bottom level project, but not the subprojects.
my folders look like this
foobar
--ear
--ejb
--spring
--web
build.gradle
settings.gradle
even if i do gradle ejb:eclipse everything appears to run correctly, i get the notices that the eclipse tasks ran in the console, but no files in the ejb project.
here is my build.gradle. What am i doing wrong?
configure(allprojects){ project ->
apply plugin: 'java'
apply plugin: 'eclipse'
sourceCompatibility = 1.6
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: "C:/IBM/WebSphere/AppServer/8.5/plugins/", include: [
'com.ibm.ws.runtime.jar',
'com.ibm.ws.wsadie/marshall.jar'
])
compile fileTree(dir: "C:/IBM/WebSphere/AppServer/8.5/runtimes/", include: [
'com.ibm.jaxrs.thinclient_8.5.0.jar',
'com.ibm.jaxws.thinclient_8.5.0.jar',
'com.ibm.ws.ejb.embeddableContainer_8.5.0.jar',
'com.ibm.ws.ejb.thinclient_8.5.0.jar',
'com.ibm.ws.jpa.thinclient_8.5.0.jar',
'com.ibm.ws.orb_8.5.0.jar'
])
}
ext {
easymockVersion = '3.3.1'
jeeVersion = '6.0'
junitVersion = '4.12'
springVersion = '4.1.5.RELEASE'
swaggerVersion = '1.3.12'
}
}
project('ear'){
description = "The EAR Project"
apply plugin: 'ear'
dependencies {
deploy project(':ejb')
deploy project(':spring')
deploy project(path: ':web', configuration: 'archives')
}
}
project('ejb'){
description = "The EJB Project"
dependencies {
compile project(':spring')
}
}
project('spring'){
description = "The Spring BL Logic"
dependencies {
runtime "org.springframework:spring-jdbc:$springVersion"
testCompile "junit:junit:$junitVersion"
testCompile "org.easymock:easymock:$easymockVersion"
testCompile "org.springframework:spring-test:$springVersion"
}
}
project('web'){
description = "The REST layer"
apply plugin: 'war'
dependencies {
compile project(':ejb')
runtime "com.wordnik:swagger-annotations:$swaggerVersion"
runtime "com.wordnik:swagger-core_2.10:$swaggerVersion"
runtime "com.wordnik:swagger-jaxrs_2.10:$swaggerVersion"
}
}
This is the output i get. It tells me the plugin fired for the subprojects but i can't figure out why it doesn't create any files
$ gradle eclipse
:eclipseClasspath
:eclipseJdt
:eclipseProject
:eclipse
:ear:eclipseClasspath
:ear:eclipseJdt
:ear:eclipseProject
:ear:eclipse
:ejb:eclipseClasspath
:ejb:eclipseJdt
:ejb:eclipseProject
:ejb:eclipse
:spring:eclipseClasspath
:spring:eclipseJdt
:spring:eclipseProject
:spring:eclipse
:web:eclipseClasspath
:web:eclipseJdt
:web:eclipseProject
:web:eclipse

Gradle: Build file should not contain a package statement

I have a gradle build project that consists of a buildSrc/build.gradle and a project-level build.gradle. The buildSrc/build.gradle compiles a jar dependency that contains a class the project-level build.gradle needs. However, when the project-level build.gradle tries to instantiate an instance of the class pulled in by buildSrc/build.gradle, the build fails. The error is:
Could not open no_buildscript class cache for build file ~/git/project/build.gradle - Build file ~/git/project/build.gradle should not contain a package statement.
In particular, the project-level build needs the DIGSauceLabsUpdater class that is in the bacon-test-utilities pulled in by buildSrc/build.gradle.
I have tried importing the bacon-test-utilities package into the project-level build and removing the package name from the class in the "def dashUpdater" line. This gave me the same build error.
Can anyone help me understand what else I need to do in order to access a class pulled in by the buildSrc/gradle.build in the the project-level build?
Thank you,
-erzsebet
Here is my buildSrc/build.gradle file:
// vim:ft=groovy
apply plugin: 'base'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'maven'
apply plugin: 'groovy'
// automated test dependencies
// ---------------------------
dependencies {
def saucerestVersion = "1.0"
compile gradleApi()
// sauce lab's REST client
compile "com.saucelabs.saucerest:saucelabs-saucerest:$saucerestVersion"
// test utilities
// Note: Needed here for DIGSauceLabsUpdater use in main build.gradle
compile "com.drillinginfo.global:bacon-test-utilities:0.+"
}
// artifacts and maven stuff
// -------------------------
repositories {
maven {
url "${project.mavenPublicUrl}/"
}
}
Here are the relevant bits of my project-level build.gradle:
// vim:ft=groovy
apply plugin: 'base'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'maven'
apply plugin: 'groovy'
// browser driver extensions for acceptance test tasks
ext.drivers = ["firefox", "chrome", "ie"]
// automated test dependencies
// ---------------------------
dependencies {
groovy "org.codehaus.groovy:groovy-all:1.8.6"
def gebVersion = "0.7.2"
def seleniumVersion = "2.31.0"
def lazerycodeVersion = "1.1"
def saucerestVersion = "1.0"
// spock
testCompile "org.codehaus.geb:geb-spock:$gebVersion"
testCompile "org.spockframework:spock-core:0.6-groovy-1.8"
// gradle plugin for test listener code
compile files('buildSrc/src/main/lib/gradle-plugins-1.2.jar')
// test utilities
testCompile "com.drillinginfo.global:bacon-test-utilities:0.+"
// Drivers
drivers.each { driver ->
testCompile "org.seleniumhq.selenium:selenium-$driver-driver:$seleniumVersion"
}
}
// automated acceptance tasks
// --------------------------
// define a TestListener implementation to report test results to Sauce Labs
// THE NEXT LINE IS WHERE THE BUILD CHOKES
def dashUpdater = new com.drillinginfo.global.test.utils.DIGSauceLabsUpdater()
// ensure the tests have access to properties passed in on the command line (-D)
tasks.withType(Test) {
gradle.addListener(dashUpdater)
}
Here is the stack trace output of my ./gradlew run task:
FAILURE: Build failed with an exception.
* What went wrong:
Could not open no_buildscript class cache for build file '/home/account/git/project/build.gradle' (/home/account/.gradle/caches/1.2/scripts/build_7hf4r97619snd7in1srbtn16n6/ProjectScript/no_buildscript).
Build file '/home/account/git/project/build.gradle' should not contain a package statement.
* Try:
Run with --info or --debug option to get more log output.
* Exception is:
org.gradle.cache.CacheOpenException: Could not open no_buildscript class cache for build file '/home/ecarmean/git/bacon/build.gradle' (/home/account/.gradle/caches/1.2/scripts/build_7hf4r97619snd7in1srbtn16n6/ProjectScript/no_buildscript).
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.open(DefaultPersistentDirectoryStore.java:54)
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.open(DefaultPersistentDirectoryStore.java:26)
at org.gradle.cache.internal.DefaultCacheFactory$CacheFactoryImpl.doOpenDir(DefaultCacheFactory.java:71)
at org.gradle.cache.internal.DefaultCacheFactory$CacheFactoryImpl.open(DefaultCacheFactory.java:110)
at org.gradle.cache.internal.DefaultCacheRepository$PersistentCacheBuilder.doOpen(DefaultCacheRepository.java:183)
at org.gradle.cache.internal.DefaultCacheRepository$PersistentCacheBuilder.doOpen(DefaultCacheRepository.java:133)
at org.gradle.cache.internal.DefaultCacheRepository$AbstractCacheBuilder.open(DefaultCacheRepository.java:120)
at org.gradle.groovy.scripts.internal.FileCacheBackedScriptClassCompiler.compile(FileCacheBackedScriptClassCompiler.java:51)
at org.gradle.groovy.scripts.internal.ShortCircuitEmptyScriptCompiler.compile(ShortCircuitEmptyScriptCompiler.java:35)
at org.gradle.groovy.scripts.internal.CachingScriptClassCompiler.compile(CachingScriptClassCompiler.java:36)
at org.gradle.groovy.scripts.DefaultScriptCompilerFactory$ScriptCompilerImpl.compile(DefaultScriptCompilerFactory.java:60)
at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:121)
at org.gradle.configuration.BuildScriptProcessor.evaluate(BuildScriptProcessor.java:38)
at org.gradle.configuration.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:43)
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:463)
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:75)
at org.gradle.configuration.ProjectEvaluationConfigurer.execute(ProjectEvaluationConfigurer.java:23)
at org.gradle.configuration.ProjectEvaluationConfigurer.execute(ProjectEvaluationConfigurer.java:21)
at org.gradle.configuration.DefaultBuildConfigurer$1.execute(DefaultBuildConfigurer.java:38)
at org.gradle.configuration.DefaultBuildConfigurer$1.execute(DefaultBuildConfigurer.java:35)
at org.gradle.api.internal.project.AbstractProject.configure(AbstractProject.java:439)
at org.gradle.api.internal.project.AbstractProject.allprojects(AbstractProject.java:434)
at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:35)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:142)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:38)
at org.gradle.launcher.exec.InProcessGradleLauncherActionExecuter.execute(InProcessGradleLauncherActionExecuter.java:39)
at org.gradle.launcher.exec.InProcessGradleLauncherActionExecuter.execute(InProcessGradleLauncherActionExecuter.java:25)
at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)
at org.gradle.launcher.cli.ActionAdapter.execute(ActionAdapter.java:30)
at org.gradle.launcher.cli.ActionAdapter.execute(ActionAdapter.java:22)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:200)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:173)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:138)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
at org.gradle.launcher.Main.doAction(Main.java:48)
at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
at org.gradle.launcher.Main.main(Main.java:39)
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32)
at org.gradle.launcher.GradleMain.main(GradleMain.java:26)
at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:33)
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:130)
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:47)
Caused by: java.lang.UnsupportedOperationException: Build file '/home/account/git/project/build.gradle' should not contain a package statement.
at org.gradle.groovy.scripts.internal.DefaultScriptCompilationHandler.compileScript(DefaultScriptCompilationHandler.java:126)
at org.gradle.groovy.scripts.internal.DefaultScriptCompilationHandler.compileToDir(DefaultScriptCompilationHandler.java:67)
at org.gradle.groovy.scripts.internal.FileCacheBackedScriptClassCompiler$CacheInitializer.execute(FileCacheBackedScriptClassCompiler.java:80)
at org.gradle.groovy.scripts.internal.FileCacheBackedScriptClassCompiler$CacheInitializer.execute(FileCacheBackedScriptClassCompiler.java:65)
at org.gradle.cache.internal.DefaultPersistentDirectoryCache.buildCacheDir(DefaultPersistentDirectoryCache.java:100)
at org.gradle.cache.internal.DefaultPersistentDirectoryCache.access$100(DefaultPersistentDirectoryCache.java:36)
at org.gradle.cache.internal.DefaultPersistentDirectoryCache$1$1.run(DefaultPersistentDirectoryCache.java:82)
at org.gradle.cache.internal.DefaultFileLockManager$DefaultFileLock.doWriteAction(DefaultFileLockManager.java:162)
at org.gradle.cache.internal.DefaultFileLockManager$DefaultFileLock.writeFile(DefaultFileLockManager.java:151)
at org.gradle.cache.internal.DefaultPersistentDirectoryCache$1.execute(DefaultPersistentDirectoryCache.java:80)
at org.gradle.cache.internal.DefaultPersistentDirectoryCache$1.execute(DefaultPersistentDirectoryCache.java:70)
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.withExclusiveLock(DefaultPersistentDirectoryStore.java:73)
at org.gradle.cache.internal.DefaultPersistentDirectoryCache.init(DefaultPersistentDirectoryCache.java:70)
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.open(DefaultPersistentDirectoryStore.java:46)
... 46 more
If you encounter this error:
Build file '...\build.gradle' should not contain a package statement.
you should check above path that mentioned and remove package statement in first line of build.gradle file.Hope helpfull.
A co-worker and I isolated the problem that caused my gradle build to fail with the "build.gradle should not contain a package statement" error. The jar file containing the dependency had both .class and .groovy files. When we recompiled the jar to include only .class files, the gradle build ran without error and was able to instantiate a class from the (troublesome!) dependency.
I also simplified my build structure by removing the buildSrc/build.gradle. It was no longer needed because there was no source being built in that directory. To pull in the (troublesome!) dependency needed in the project-level build.gradle, I used a buildScript block.
Thank you, Peter Niederwieser, for reading and responding to the question!
Here are the relevant bits of the final build script:
// vim:ft=groovy
import com.drillinginfo.global.test.utils.DIGSauceLabsUpdater
apply plugin: 'base'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'maven'
apply plugin: 'groovy'
// automated test dependencies
// ---------------------------
dependencies {
groovy "org.codehaus.groovy:groovy-all:1.8.6"
def gebVersion = "0.7.2"
def seleniumVersion = "2.31.0"
def lazerycodeVersion = "1.1"
def saucerestVersion = "1.0"
// spock
testCompile "org.codehaus.geb:geb-spock:$gebVersion"
testCompile "org.spockframework:spock-core:0.6-groovy-1.8"
// test utilities
testCompile "com.drillinginfo.global:bacon-test-utilities:0.+"
// Drivers
drivers.each { driver ->
testCompile "org.seleniumhq.selenium:selenium-$driver-driver:$seleniumVersion"
}
}
buildscript {
repositories {
maven {
url "${project.mavenPublicUrl}/"
}
}
dependencies {
classpath group: 'com.drillinginfo.global', name: 'bacon-test-utilities', version: '0.0.1+17'
}
}
/ automated acceptance tasks
// --------------------------
// define a TestListener implementation to report test results to Sauce Labs
def dashUpdater = new DIGSauceLabsUpdater()
// ensure the tests have access to properties passed in on the command line (-D)
tasks.withType(Test) {
gradle.addListener(dashUpdater)
}
I was running into this issue with the following in build.gradle:
buildscript {
dependencies {
classpath fileTree(
dir: "some/directory",
include: '**/*.jar')
}
}
some/directory had source jars so the fix was:
buildscript {
dependencies {
classpath fileTree(
dir: "some/directory",
include: '**/*.jar',
exclude: '**/-sources.jar')
}
}

Resources