could not find method compile() for arguments - gradle

I'm trying to execute some .sql scripts and then deploy web app using gradle tomcat plugin.
But when I make any attempt to run gradle I've got an error
My buildscript looks like this
buildscript {
//repository location
repositories {
mavenCentral()
jcenter()
}
//dependencies
//did not divide them into runtime&compile
dependencies {
//aspectJ dependencies
compile 'org.aspectj:aspectjlib:1.6.2'
compile 'org.aspectj:aspectjrt:1.7.4'
compile 'org.aspectj:aspectjweaver:1.7.4'
//servlet
compile 'javax.servlet:javax.servlet-api:3.0.1'
//jdbc postresql
compile 'org.postgresql:postgresql:9.2-1004-jdbc4'
//commons dbcp
compile 'commons-dbcp:commons-dbcp:1.2.2'
//spring & spring MVC dependencies
compile 'org.springframework:spring-core:' + spring_version
compile 'org.springframework:spring-web:' + spring_version
compile 'org.springframework:spring-webmvc:' + spring_version
compile 'org.springframework:spring-jdbc:' + spring_version
compile 'org.springframework:spring-aspects:' + spring_version
//spring security
compile 'org.springframework.security:spring-security-core:' + spring_security_version
compile 'org.springframework.security:spring-security-web:' + spring_security_version
compile 'org.springframework.security:spring-security-config:' + spring_security_version
//JSTL
compile 'jstl:jstl:1.2'
//slf4j-log4j
compile 'org.slf4j:slf4j-api:1.7.0'
compile 'org.slf4j:slf4j-log4j12:1.7.0'
compile 'log4j:log4j:1.2.17'
//mybatis
compile 'org.mybatis:mybatis:3.2.4'
compile 'org.mybatis:mybatis-spring:1.2.2'
//gson
compile 'com.google.code.gson:gson:2.2.4'
//validation jsr303
compile 'javax.validation:validation-api:1.0.0.GA'
//junit4(test?)
compile 'junit:junit:4.11'
//spring test(test?)
compile 'org.springframework:spring-test:' + spring_version
//java mail
compile 'javax.mail:mail:1.4'
//tomcat plugin
def tomcatVersion = '7.0.53'
tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
"org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}"
tomcat("org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}") {
exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj'
}
//additional classpath
classpath 'org.gradle.api.plugins:gradle-tomcat-plugin:1.2.3'
classpath 'org.postgresql:postgresql:9.2-1004-jdbc4'
}
}
In build.gradle there are also several tasks and several apply plugin.
What's the problem? Full stack trace
My build.gradle is in a project folder.

The build script is mixing up buildscript dependencies (i.e.
dependencies of the build itself; typically this means Gradle plugins
with regular dependencies (i.e. dependencies of the code to be compiled/run).
2 needs to go into dependencies { ... }, not into buildscript { dependencies { ... } }.
Everything but the classpath dependencies are regular dependencies.

I get this error sometimes after Android Studio does some operation that tries to automatically add things to my build.gradle file, and then it messes up lines of code in the dependencies block that end with quotes or double-quotes. So I end up with a line like this:
def gpsVersion = '9.4.0'
compile "com.google.android.gms:play-services-wearable:${gpsVersion}" compile "com.google.android.gms:play-services-places:${gpsVersion}"
And as you can see it looks like the method compile has many arguments now. Fix the line spacing and resync to fix it.

Related

CompileJava failed to find metamodel and failed

I've has a project for at least a year and would compile fine. now when i try to compile the metamodels are missing and the compilejava task is failing. I'm not sure if the issues is because there is a version issue or what. keep in mind that before hand i had no issue with running the build with the current gradle build script and project file structure.
the code is in java with netBeans:
Product Version: NetBeans IDE 8.2 (Build 201609300101)
Updates: NetBeans IDE is updated to version NetBeans 8.2 Patch 2
Java: 1.8.0_171; Java HotSpot(TM) 64-Bit Server VM 25.171-b11
Runtime: Java(TM) SE Runtime Environment 1.8.0_171-b11
System: Windows 10 version 10.0 running on amd64; Cp1252; en_US (nb)
Gradle Support 1.4.4
i've attempted to "set the generated path" but that didn't work.
i've also tried to create me own copies of the metamodel class then reference it in the dynamic query builder. it would compile but the when i tested the query and i keep getting a null pointer exception.
if i ctrl click the metamodel in the class file using the metamodel it loads the metamodel class file i think there is some issue with the generator creating the metamodel object on compile.
apply plugin: 'java'
apply plugin: 'war'
sourceCompatibility = '1.8'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
war.archiveName "ApplicationWarehouseService.war"
war {
webInf {from 'src/main/resources/application.xml' }
}
if (!hasProperty('mainClass')) {
ext.mainClass = 'test'
}
repositories {
mavenCentral()
maven {
url "http://jaspersoft.artifactoryonline.com/jaspersoft/third-party-ce-artifacts/"
}
}
dependencies {
compile 'javax.servlet:javax.servlet-api:4.0.0'
compile 'commons-validator:commons-validator:1.6'
compile 'org.springframework:spring-webmvc:5.0.5.RELEASE'
compile 'org.springframework.security:spring-security-web:5.0.4.RELEASE'
compile 'org.springframework.security:spring-security-config:5.0.4.RELEASE'
compile 'org.springframework:spring-jdbc:5.1.6.RELEASE'
compile 'org.springframework:spring-aop:5.1.6.RELEASE'
compile 'org.springframework:spring-context:5.1.6.RELEASE'
compile 'org.springframework:spring-context-support:5.1.6.RELEASE'
compile 'org.springframework.data:spring-data-jpa:2.1.6.RELEASE'
compile 'org.springframework:spring-orm:5.1.6.RELEASE'
compile 'com.microsoft.sqlserver:mssql-jdbc:6.4.0.jre8'
compile 'org.hibernate:hibernate:3.5.4-Final'
compile 'org.hibernate:hibernate-core:5.4.2.Final'
compile 'org.hibernate:hibernate-jpamodelgen:5.4.3.Final'
compile 'org.aspectj:aspectjrt:1.9.0'
compile 'org.aspectj:aspectjweaver:1.9.0'
compile 'org.apache.tomcat:tomcat-jdbc:9.0.7'
compile 'com.fasterxml.jackson.core:jackson-databind:2.9.5'
compile 'commons-fileupload:commons-fileupload:1.3.3'
compile 'javax.mail:javax.mail-api:1.6.1'
compile 'javax:javaee-api:8.0'
compile 'javax.servlet:jstl:1.2'
compile 'org.hibernate.validator:hibernate-validator:6.0.9.Final'
compile 'org.apache.logging.log4j:log4j-core:2.11.0'
compile files('C:/Program Files (x86)/Microsoft JDBC Driver 4.1 for SQL Server/sqljdbc_4.1/enu/jre7/sqljdbc41.jar')
//compile 'com.lowagie:itext:4.2.2'
compile 'com.lowagie:itext:2.1.7'
compile 'net.sf.jasperreports:jasperreports:6.1.0'
// compile 'com.itextpdf:itextpdf:5.5.13'
// compile 'net.sf.jasperreports:jasperreports:6.5.1'
compile 'javax.money:money-api-bp:1.0'
compile 'org.json:json:20180130'
compile 'javax.xml.bind:jaxb-api:2.3.0'
compile group: 'ar.com.fdvs', name: 'DynamicJasper', version: '5.1.1'
compile group: 'ar.com.fdvs', name: 'DynamicJasper-core-fonts', version: '1.0'
testCompile group: 'junit', name: 'junit', version: '4.10'
testCompile 'org.springframework:spring-test:5.0.5.RELEASE'
}
configurations.all*.dependencies*.withType(ModuleDependency)*.each {
it.exclude group: "org.bouncycastle", module: "*"
it.exclude group: "bouncycastle", module: "*"
}
ideally i'd like to have my project create the metamodels and compile successfully.
I found the Solution I Added
annotationProcessor('org.hibernate:hibernate-jpamodelgen:5.4.3.Final')
in the dependencies section. Compiled just fine.

How can I clone a repo from GitHub using gradle?

I have a project which depends on other repos. My goal is to write a gradle task that clones the required repos automatically.
The problem I am having is that when I run my task, gradlew fails because it tries to compile the project dependencies before running my task. Here is what I have:
settings.gradle
include ':app'
include 'testRepo'
project(':testRepo').projectDir = new File('../testRepo')
build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'org.ajoberstar:gradle-git:1.5.1'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
build.gradle(app)
task clone << {
Grgit.clone(dir: file('../testRepo'), uri: "https://github.com/fakeAccount/testRepo.git")
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile project(':testRepo')
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.google.android.gms:play-services-maps:8.4.0'
compile 'com.google.android.gms:play-services-location:8.4.0'
}
When I do ./gradlew clone I get:
"Cannot evaluate module testRepo : Configuration with name 'default' not found"
This is because it tries to compile the testRepo project before cloning from GitHub. If I take out the compile project(':testRepo') it works fine.
Any ideas as to how to make this work?

Android Studio 2.2: Gradle: Fixplugin version and sync project

Gradle problem
I"m update build.gradle:
`}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0-alpha1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
and
gradle-wrapper.propertie:`
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-all.zip
app\build.gradel:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha1'
testCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support:support-annotations:23.4.0'
}
Location C:/Software/gardle2.14/gradle-2.14
I"m get this note:
Error:(1, 0) Plugin is too old, please update to a more recent version, or set ANDROID_DAILY_OVERRIDE environment variable to "f45c7e54f5c7108ea208060be3303c44dd2ae899"
Thanks for support

Gradle Build Error

My build failed due to this error:
A problem occurred evaluating project ':DBSupport'. > Could not find
method providedCompile() for arguments [project ':Core:Platform '] on
project ':DBSupport'.
Any idea what that means?
description = 'DBSupport main component of DBSupportTool'
dependencies {
providedCompile project(':Core:Platform')
providedCompile project(':Core:Verification')
providedCompile project(':DBSupportWeb')
providedCompile project(':DBSupportEJB')
compile(group: 'commons-lang', name: 'commons-lang', version:'1.0.1') {
/* This dependency was originally in the Maven provided scope, but the project was not of type war.
This behavior is not yet supported by Gradle, so this dependency has been converted to a compile dependency.
Please review and delete this closure when resolved. */
}
compile(group: 'commons-logging', name: 'commons-logging', version:'1.0.4') {
/* This dependency was originally in the Maven provided scope, but the project was not of type war.
This behavior is not yet supported by Gradle, so this dependency has been converted to a compile dependency.
Please review and delete this closure when resolved. */
}
compile(group: 'javax', name: 'j2ee', version:'1.0') {
/* This dependency was originally in the Maven provided scope, but the project was not of type war.
This behavior is not yet supported by Gradle, so this dependency has been converted to a compile dependency.
Please review and delete this closure when resolved. */
}
I assume these modules should in fact be treated as provided (e.g. should not be packages in a WAR archive). If not just change it to compile.
providedCompile configuration is not available in Gradle out of the box. If this is a web module you can just add/apply a war plugin:
apply plugin: 'war'
If not you should be able to add this configuration manually:
configurations {
providedCompile
}
dependencies {
providedCompile project(':Core:Platform')
...
}
sourceSets.main.compileClasspath += configurations.providedCompile
sourceSets.test.compileClasspath += configurations.providedCompile
sourceSets.test.runtimeClasspath += configurations.providedCompile
There is also a propdeps-plugin which claims to do the same thing transparently.
To define a dependency provided as in Maven you need to go the following way:
project(':webgui') {
apply plugin: 'war'
dependencies {
compile project (':domain')
providedCompile 'javax:javaee-api:6.0'
}
}
or an other way would be in case of a project (module) like this:
dependencies {
compile module(":compile:1.0") {
dependency ":compile-transitive-1.0#jar"
dependency ":providedCompile-transitive:1.0#jar"
}
providedCompile "javax.servlet:servlet-api:2.5"
providedCompile module(":providedCompile:1.0") {
dependency ":providedCompile-transitive:1.0#jar"
}
runtime ":runtime:1.0"
providedRuntime ":providedRuntime:1.0#jar"
testCompile "junit:junit:4.11"
moreLibs ":otherLib:1.0"
}

Exclude unneccesarry jar in FAT jar using gradle

I am building the FAT jar using gradle-1.3 version and building the
FAT jar using this below properties
jar {
from configurations.compile.collect { it.isDirectory() ? it : zipTree(it)
}
Dependencies AS FOLLOWS
dependencies {
compile fileTree(dir:'/trunk/Solutions/Seismic/Source/Binaries/CommonFunctions/build/libs', include: '*.jar')
compile "org.apache.hadoop:hadoop-core:1.0.3"
compile "commons-collections:commons-collections:3.2.1"
compile "commons-configuration:commons-configuration:1.6"
compile "commons-discovery:commons-discovery:0.2"
compile "commons-lang:commons-lang:2.4"
compile "commons-logging:commons-logging:1.1.1"
compile "commons-logging:commons-logging:1.0.4"
compile "log4j:log4j:1.2.16"
compile "com.vividsolutions:jts:1.8"
compile "commons-net:commons-net:1.4.1"
compile "org.apache.hadoop:hadoop-core:1.0.3"
compile "commons-httpclient:commons-httpclient:3.0.1"
compile "org.mortbay.jetty:servlet-api:2.5-20081211"
compile "org.apache.hbase:hbase:0.94.0"
compile "org.apache.zookeeper:zookeeper:3.4.3"
}
But still by jar is included with following jar as reference
jay,
jline,
jni,
jnr,
jruby,
junit,
junit3.8.1
But i don't want to include these jars
You can exclude the dependencies by adding this to the bottom of your build:
configurations.all*.dependencies*.withType(ModuleDependency)*.each {
it.exclude group: "org.jline", module: "jline"
it.exclude ...
}
This will iterate over the dependencies of all configurations and exclude the modules that you don't want to include.
If you want to exclude all transitive dependencies, it is easier to set the transitivity to false for the compile configuration:
configurations.compile.transitive = false

Resources