Could not find method cargo() for arguments - gradle

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')
}

Related

Could not find method compile() for a multi module project

dependencies {
compile project('client')
compile project('-cache
')
Now when I comment out compile project('product-cache-client') it moves to the next one and compains about that.
I tried to add it to gradle.settings in that module like so:
include('client')
include('cache')
But I still get the same error. I even tried adding this to the gradle.settings
project('lib/cache').projectDir = "$rootDir/lib/cache" as File
And still get the same result.
Gradle 4.4
main gradle.build file:
subprojects {
dependencies {
compile project('client')
compile project('cache')
}
repositories{
jcenter()
mavenCentral()
}
}
configure(subprojects){
apply plugin: 'maven'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'
}
repositories {
}
buildscript {
ext {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
}
dependencies {
jcenter()
mavenCentral()
}
Add the java plugin on top of your parent build, for me this works:
apply plugin:'java'
It is recommended here - the second answer Could not find method compile() for arguments Gradle
And also switch the 'dependencies' with 'repositories' - at least in the sample of build.gradle you wrote here they are switched.
when you define dependency as compile then it can not be accessible at the runtime. If you run the project through IDE then it works but when you run with gradle bootRun or mvn spring-boot:run command then above error will throw. So have to just replace compile with implementation.
dependencies {
implementation project('client')
implementation project('cache')
}

Gradle 2.8 cargo war deployment compile method not found

le 'C:\Users\naresh.vatsal\workspace_spring_jan14\SpringMvcUsingGradle\build.gradle' line: 28
ent wrong:
m occurred evaluating root project 'SpringMvcUsingGradle'.
not find method compile() for arguments [org.springframework:spring-context:4.0.0.RELEASE] on org.gradle.api.internal.artifacts.dsl.dependencies.Default
cyHandler_Decorated#434c4af3.
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'war'
apply plugin: 'com.bmuschko.tomcat-base'
apply plugin: 'com.bmuschko.cargo'
ext.tomcatVersion = '7.0.67'
ext.cargoVersion = '1.1.3'
sourceCompatibility = 1.7
buildscript
{
repositories {
maven {
url "https://plugins.grdev.net/m2/"
mavenCentral()
}
}
dependencies {
classpath "com.bmuschko:gradle-tomcat-plugin:2.2.4"
classpath 'com.bmuschko:gradle-cargo-plugin:2.2'
}
dependencies {
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 = '' `enter code here`
}

Gradle build for Java project is failing

Below build.gradle file for java project is failing
apply plugin: 'java'
apply plugin: 'eclipse'
sourceCompatibility = 1.5
version = '1.0'
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '2.+'
testCompile "log4j:log4j:1.2.9"
testCompile 'org.testng:testng:6.8'
}
test {
// enable TestNG support
task testNGTests(type: Test) {
useTestNG() {
suites 'src/test/resources/testng.xml'
useDefaultListeners = true
}
}
}
Error:
Couldnot find property 'projectDir' on org.gradle.api.tasks.testing.testng.TestNGOptions_Decorated#1595f1bb.
Then I tried in using setting.gradle file with below code:
rootProject.name = 'AutoTest_Gradle'
project(':AutoTest_Gradle').projectDir = 'C:/workspace/AutoTest_Gradle'
Here AutoTest_Gradle is the project name.Then it is failed with below error:
Where:
Settings file 'C:\workspace\AutoTest_Gradle\settings.gradle
What went wrong:`enter code here
A problem occurred evaluating settings 'AutoTest_Gradle'.
Project with path ':AutoTest_Gradle' could not be found.
Can anyone help on this?

Gradle Error: No method add() found for arguments

So I'm adding a custom plugin to Gradle, specifically jmeter. https://github.com/kulya/jmeter-gradle-plugin
I thought everything worked, but now this error is occuring:
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\rstraubel\Documents\DataCentral\build.gradle' line: 21
* What went wrong:
A problem occurred evaluating root project 'DataCentral'.
> Could not find method add() for arguments [jmeterEditor, class com.github.kulya.gradle.plugins.jmeter.JmeterRunGuiTask] on task set.
Line 21 is just where I call plugin: 'jmeter'
Everything else specified in the github has been done. Any ideas? Thanks
Edit: Full Build.gradle
buildscript {
ext {
springBootVersion = '1.0.2.RELEASE'
}
repositories {
mavenCentral()
maven { url "http://repo.spring.io/libs-milestone"}
mavenLocal()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("com.github.kulya:jmeter-gradle-plugin:1.3.1-2.6")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
apply plugin: 'idea'
apply plugin: 'sonar-runner'
apply plugin: 'jmeter'
jar {
baseName = 'datacentral'
version = '0.0.1-SNAPSHOT'
}
repositories {
mavenCentral()
maven { url "http://repo.spring.io/libs-milestone" }
maven { url "http://m2.neo4j.org" }
}
dependencies {
compile "org.springframework.boot:spring-boot-starter-web:${springBootVersion}"
compile "org.springframework.boot:spring-boot-starter-data- mongodb:${springBootVersion}"
compile "com.fasterxml.jackson.core:jackson-databind"
compile "org.springframework.boot:spring-boot-starter-web"
compile "org.springframework.data:spring-data-mongodb"
compile "org.mongodb:mongo-java-driver:2.12.0-rc0"
compile "org.springframework.data:spring-data-rest-webmvc"
testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}"
}
jmeterRun.configure {
jmeterTestFiles = [file("src/test/jmeter/TestCases.jmx")]
}
sonarRunner {
sonarProperties {
property "sonar.host.url", "http://hawkeye.control-tec.com:9000"
property "sonar.jdbc.url", "jdbc:mysql://bluestreak.qualifier.control-tec.com:3306/sonar?useUnicode=true&characterEncoding=utf8"
property "sonar.jdbc.driverClassName", "com.mysql.jdbc.Driver"
property "sonar.jdbc.username", "sonar"
property "sonar.jdbc.password", "sonar-pass"
property "sonar.projectKey", "com.controltec.incontrol.qualifier:Data-Central"
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.0'
}
Most likely, the jmeter plugin hasn't been updated to support Gradle 2.0. You can verify by trying with 1.12.

No persistent classes found when integration test in Gradle

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.

Resources