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

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

Related

SonarQube - java/groovy multimodule project scan

I have:
SonarQube v5.6 + Groovy plugin
gradle 3.5
org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.5
Configuration:
def sourceProjects = allprojects.findAll { it.file('src/main').exists() }
configure(sourceProjects) {
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: "org.sonarqube"
sourceSets.main.java.srcDirs = []
sourceSets.main.groovy.srcDirs = ['src/main/java', 'src/main/groovy']
sourceCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
}
dependencies {
compile lib.groovy_core
}
}
Project structure:
rootDir
apps
app-backend
app-ui
modules
module 1
module 2
module 3
Whenever I run: $ ./gradlew sonarqube what happens is when it goes through different modules, it does not aggregate sonar reports. It throws in last module scan and overwrites anything that was already stored. So after running this, I just get the results for last modules that gradle executor processed. Can something be done about that?
For what its worth I solved this issue by applying sonar cube to the root project only:
project(':') {
apply plugin: 'org.sonarqube'
}

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

How to get Gradle Spring dependency plugin to work?

Because I'm such a newb at this, the problem is context. Their example doesn't match my build. I've installed the jar locally so it should definitely be available.
My project looks like:
allprojects {
apply plugin: 'maven'
apply plugin: "io.spring.dependency-management"
group = 'com.wnp'
version = '6.5.0-SNAPSHOT'
}
subprojects {
apply plugin: 'java'
sourceCompatibility = System.getProperty("java.version")
targetCompatibility = System.getProperty("java.version")
repositories {
mavenLocal()
mavenCentral()
jcenter()
}
dependencyManagement {
imports {
mavenBom 'org.springframework.ws:spring-ws:2.1.4.RELEASE'
mavenBom 'org.jboss.as:jboss-as-jms-client-bom:7.5.0.Final-redhat-21'
}
dependencies {
dependency "antlr:antlr:2.7.7"
}
}
apply plugin: "io.spring.dependency-management"
Their project looks like:
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE"
}
}
apply plugin: "io.spring.dependency-management"
What I'm getting from the system is :
Caused by: org.gradle.api.plugins.UnknownPluginException: Plugin with
id 'io.spring.dependency-management' not found.
Clues? What does "buildscript" represent? Is that a task? I've tried putting the "dependencies" section just about everywhere. Same goes with the "apply plugin:" line. Is my dependencyManagement section in the right place? One of the things I keep seeing is "dependencies cannot be applied to closure" which is pretty unhelpful as far as error messages go.
What you need to do is to define a dependency for build.gradle itself that has the plugin you're looking for. It may be e.g.:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'io.spring.gradle:dependency-management-plugin:0.5.3.RELEASE'
}
}
allprojects {
apply plugin: 'maven'
apply plugin: "io.spring.dependency-management"
group = 'com.wnp'
version = '6.5.0-SNAPSHOT'
}
Take a look at the official user guide, section called "external dependencies". According to it:
If your build script needs to use external libraries, you can add them to the script's classpath in the build script itself. You do this using the buildscript() method, passing in a closure which declares the build script classpath.
In your case,a plugin is an external dependency, and you have to provide buildscript section for all the project, which need to apply this plugin.

Spring Boot Tutorial doesn't work with multi project gradle setup

i get a strange behaviour (at least for me :D) when I switch from the gradle file located in https://spring.io/guides/gs/serving-web-content/ to a multi project gradle file setup.
build.gradle in root directory
//Applied to all projects.
allprojects {
apply plugin: 'eclipse'
apply plugin: 'idea'
group = 'de.test.platform'
version = '0.1'
}
subprojects {
//Currently all subprojects are also java projects. If this changes we
//need to move it into the corresponding projects
apply plugin: 'java'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenLocal()
mavenCentral()
}
idea {
module {
downloadSources = true
downloadJavadoc = false
}
}
}
idea {
project {
jdkName = '1.8'
languageLevel = '1.8'
}
}
build.gradle in sub directory frontend (thus sub project called :frontend)
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.5.RELEASE")
}
}
apply plugin: 'war'
apply plugin: 'spring-boot'
jar {
baseName = 'crowdio-frontend'
version = '0.1.0'
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
testCompile("junit:junit")
}
when I run gradle bootRun and navigate to http://localhost:8080/greeting as in the tutorial i get a infinite loop error. If i change the template from greeting.html to hello.html and return hello instead of greeting in the controller greeting() action i get an 404 Error.
The template is stored in project_root/frontend/src/main/resources/templates/greeting.html
It seems like that for whatever Reason spring boot can decide on thymeleaf with the exact structure of the gradle build file like in the tutorial. However if you switch to a multi project setup you need to add
compile("org.thymeleaf:thymeleaf-spring4")
as a dependency.

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.

Resources