The structure of my project looks like this https://zapodaj.net/d96c686a2cabe.png.html. There are 4 build.gradle files. One generally in the project and one for each module.
The main build.gradle file looks like this REST-Web-Service -> build.gradle
buildscript {
ext {
springBootVersion = '2.0.0.RELEASE'
}
repositories {
jcenter()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
def javaProjects = subprojects.findAll {
it.name == "common" & it.name == "core" && it.name == "web"
}
allprojects {
apply plugin: 'idea'
apply plugin: 'eclipse'
repositories {
jcenter()
}
}
idea {
project {
jdkName = "1.8"
languageLevel = "1.8"
vcs = "Git"
}
}
configure(javaProjects) {
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
...
}
}
However, the build.gradle file in the common module looks like this REST-Web-Service -> common -> build.gradle
group = 'com.common'
dependencies {
compile("com.fasterxml.jackson.core:jackson-databind")
compile("org.hibernate:hibernate-validator")
compile("com.google.guava:guava")
compile group: 'commons-validator', name: 'commons-validator', version: '1.6'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.6'
compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.8.0'
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.8.0'
}
When building a project with the Gradle tool, I get an error
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\Jonatan\Documents\GitHub\REST-Web-Services\common\build.gradle' line: 6
* What went wrong:
A problem occurred evaluating project ':common'.
> Could not find method api() for arguments [com.fasterxml.jackson.core:jackson-databind] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 0s
Could not find method api() for arguments [com.fasterxml.jackson.core:jackson-databind] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Related
This is my build.gradle file
buildscript {
ext {
springBootVersion = '1.4.2.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'yBayApplication'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
springBoot {
mainClass = "com.ybayApplication.customerAccount.CustomerServiceApplication"
}
dependencies {
compile('org.springframework.cloud:spring-cloud-starter-eureka-server:1.2.3.RELEASE')
compile('org.springframework.cloud:spring-cloud-starter-zuul')
compile group: 'com.netflix.zuul', name: 'zuul-core', version: '2.0.0-rc.1'
compile group: 'com.netflix.governator', name: 'governator-archaius', version: '1.6.0'
compile group: 'io.reactivex', name: 'rxjava-string', version: '0.22.0'
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("com.h2database:h2")
testCompile("junit:junit")
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:Brixton.BUILD-SNAPSHOT"
}
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
}
}
And this is the error message, I am receiving while building the gradle.
Gradle Distribution: Local installation at C:\gradle\gradle-3.4.1
Gradle Version: 3.4.1
Java Home: C:\Program Files (x86)\Java\jdk1.8.0_121
JVM Arguments: None
Program Arguments: None
Gradle Tasks: clean build
:clean UP-TO-DATE
:compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all dependencies for configuration ':detachedConfiguration5'.
> Could not find com.netflix.governator:governator-archaius:1.6.0.
Searched in the following locations:
https://repo1.maven.org/maven2/com/netflix/governator/governator-archaius/1.6.0/governator-archaius-1.6.0.pom
https://repo1.maven.org/maven2/com/netflix/governator/governator-archaius/1.6.0/governator-archaius-1.6.0.jar
https://repo.spring.io/snapshot/com/netflix/governator/governator-archaius/1.6.0/governator-archaius-1.6.0.pom
https://repo.spring.io/snapshot/com/netflix/governator/governator-archaius/1.6.0/governator-archaius-1.6.0.jar
https://repo.spring.io/milestone/com/netflix/governator/governator-archaius/1.6.0/governator-archaius-1.6.0.pom
https://repo.spring.io/milestone/com/netflix/governator/governator-archaius/1.6.0/governator-archaius-1.6.0.jar
Required by:
project :
project : > com.netflix.zuul:zuul-core:2.0.0-rc.1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 1.77 secs
As you can see in the build.gradle file, I have added the missing dependency as well. I am tying to implement a Zuul filter based on this example in gradle https://spring.io/guides/gs/routing-and-filtering/.
On the first look, it looks like you need to remove the
compile group: 'com.netflix.zuul', name: 'zuul-core', version: '2.0.0-rc.1'
The compile('org.springframework.cloud:spring-cloud-starter-zuul') is dependent on zuul core so it will download it.
Additionally, for the governator-archaius I don't see the version 1.6.0.
I think you meant 1.16.0. Look at the link here to grab the accurate version https://mvnrepository.com/artifact/com.netflix.governator/governator-archaius
Let me know if this solves your problem.
I am new for IntelliJ and Gradle, but I have enough experience on Java and Eclipse. I generated some java classes from wsdl file. I put them under src/main/resources with a folder name - "generatedsources".
I try to prevent checkstyle for this folder and its subfolders like src/main/resources/generatedsources/* with gradle on IntelliJ.
I tried some lines such;
task checkstyle(type: Checkstyle) {
source 'src'
// include '**/*.java'
// exclude '**/gen/**'
// exclude '**/R.java'
// exclude '**/BuildConfig.java'
exclude 'src/main/resources/generatedsources/**'
}
But I'm failed again.
build.gradle;
apply plugin: 'war'
apply plugin: 'jetty'
apply plugin: 'checkstyle'
apply plugin: 'java'
apply plugin: 'no.nils.wsdl2java'
sourceCompatibility = 1.7
version = '1.0'
...
buildscript{
repositories{
jcenter()
mavenCentral()
}
dependencies {
classpath 'no.nils:wsdl2java:0.10'
}
}
task checkstyle(type: Checkstyle) {
source 'src'
// include '**/*.java'
// exclude '**/gen/**'
// exclude '**/R.java'
// exclude '**/BuildConfig.java'
exclude 'src/main/resources/generatedsources/**'
}
EDIT - After recommendations(but still failed!):
apply plugin: 'war'
apply plugin: 'jetty'
apply plugin: 'checkstyle'
apply plugin: 'java'
apply plugin: 'no.nils.wsdl2java'
sourceCompatibility = 1.7
version = '1.0'
description = """BLABLABLA_application"""
war.archiveName = "BLABLABLA.war"
configurations{
deployerJars
}
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.codehaus.jackson', name: 'jackson-core-asl', version: '1.9.3'
compile group: 'org.codehaus.jackson', name: 'jackson-mapper-asl', version: '1.9.3'
compile group: 'org.springframework', name: 'spring-core', version:'4.0.0.RELEASE'
compile group: 'org.springframework', name: 'spring-web', version:'4.0.0.RELEASE'
compile 'log4j:log4j:1.2.17'
compile 'com.sun.xml.ws:jaxws-rt:2.2.8'
compile 'org.jvnet.jax-ws-commons.spring:jaxws-spring:1.9'
compile group: 'org.springframework', name: 'spring-webmvc', version:'4.0.0.RELEASE'
providedCompile group: 'javax.servlet', name: 'servlet-api', version:'2.5'
testCompile group: 'junit', name: 'junit', version: '4.11'
deployerJars "org.apache.maven.wagon:wagon-http:2.2"
}
jar {
manifest {
attributes 'Implementation-Title': 'BLABLABLA', 'Implementation-Version': version
}
}
uploadArchives {
repositories {
flatDir {
dirs 'repos'
}
}
}
buildscript{
repositories{
jcenter()
mavenCentral()
}
dependencies {
classpath 'no.nils:wsdl2java:0.10'
}
}
wsdl2java{
wsdlsToGenerate = [
["$projectDir/src/main/resources/BLABLABLA.wsdl"]
]
generatedWsdlDir = file("$projectDir/src/gen/java")
wsdlDir = file("$projectDir/src/main/resources")
}
wsdl2javaExt {
cxfVersion = "2.5.1"
}
tasks.withType(Checkstyle) {
exclude '**/your/generated/package/goes/here**'
}
checkstyleMain.exclude '**/your/generated/package/goes/here**'
"exclude" in tasks.withType and "checkstyleMain" causes an error such as "cannot resolve symbol"!
When checkstyle plugin is applied custom tasks are delivered along with it (see here), so instead of adding custom task with type Checkstyle configure the shipped one. This is how it should be done:
tasks.withType(Checkstyle) {
exclude '**/your/generated/package/goes/here**'
}
You can also configure a particular task, not all:
checkstyleMain.exclude '**/your/generated/package/goes/here**'
Also this is not good practice to put generated sources under src/main/resources. Typically such files goes to e.g. src/gen/java
I followed some comments and make it work add this in file build.gradle
checkstyle {
config = rootProject.resources.text.fromFile("${project.projectDir}/checkstyle-8.34_google_checks.xml")
toolVersion = '8.34'
ignoreFailures = false
maxWarnings = 0
}
checkstyleMain
.exclude('com/examples/gen/api/*.java')
.exclude('com/examples/gen/model/*.java')
.exclude('com/examples/gen/auth/*.java')
You can only exclude a folder that is in the source set. That is something that had not been mentioned and it caused me to struggle since I am using Intellij. The generated files are in the build/ folder which is on the same level as src/. I tried excluding the build folder for a while but there was no effect. The only solution was to specify the source folder. Since the build folder is not under src (the source folder), it worked immediately.
checkstyleMain.source = "src/main/java"
I found the solution here: Specify excludes to Checkstyle task
I had lots of issues with checkStyle & pmd + QueryDSL
A final solution for me was not to exclude generated sources, but clean them after assemble task: no sources - nothing to analyze! :)
assemble {
finalizedBy cleanQuerydslSourcesDir
}
For kotlin dsl use
tasks.withType<Checkstyle>() {
exclude("**/com/generated/*.java")
}
I'm new to Gradle and I don't know what to do.
Here is Quasar docs about how to install Quasar through Gradle: Quasar Docs
There is also a template project in the page: Template Gradle Project
Finally this is my build.gradle:
group 'TGAdminsBot'
version '0.1'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'application'
sourceCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://jitpack.io" }
}
mainClassName = "Launcher"
idea {
module
{
downloadJavadoc = true
downloadSources = true
}
}
dependencies {
compile 'co.paralleluniverse:quasar-core:0.7.4:jdk8'
compile 'com.fasterxml.jackson.core:jackson-databind:2.7.4'
compile 'com.fasterxml.jackson.core:jackson-core:2.7.4'
//compile 'com.github.User:Repo:Tag'
//compile 'com.mashape.unirest:unirest-java:1.4.9'
compile 'co.paralleluniverse:comsat-httpclient:0.7.0'
compile group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.2.0'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
configurations {
quasar
}
task runQuasar {
jvmArgs "-javaagent:${configurations.quasar.iterator().next()}"
}
run.dependsOn runQuasar
And I get this Error:
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\Sobhan\Documents\IntelliJIDEAProjects\TGAdminsBot\build.gradle' line: 39
* What went wrong:
A problem occurred evaluating root project 'TGAdminsBot'.
> java.util.NoSuchElementException (no error message)
So What should I do? I'm again sorry to ask this question but I'm new to Gradle and I Googled so much before posting this question. Thanks
There were three problems.
configurations were defined before dependencies.
Two lines were needed in dependencies:
compile 'co.paralleluniverse:quasar-core:0.7.4:jdk8'
quasar 'co.paralleluniverse:quasar-core:0.7.4:jdk8'
Lack of this block:
tasks.withType(JavaExec){
jvmArgs "-javaagent:${configurations.quasar.iterator().next()}"
}
Finally this is final build.gradle:
group 'TGAdminsBot'
version '0.1'
apply plugin: 'java'
apply plugin: 'idea'
sourceCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://jitpack.io" }
}
idea {
module
{
downloadJavadoc = true
downloadSources = true
}
}
configurations {
quasar
}
dependencies {
compile 'co.paralleluniverse:quasar-core:0.7.4:jdk8'
quasar 'co.paralleluniverse:quasar-core:0.7.4:jdk8'
compile 'com.fasterxml.jackson.core:jackson-databind:2.7.4'
compile 'com.fasterxml.jackson.core:jackson-core:2.7.4'
compile 'co.paralleluniverse:comsat-httpclient:0.7.0'
compile group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.2.0'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
tasks.withType(JavaExec)
{
jvmArgs "-javaagent:${configurations.quasar.iterator().next()}"
}
task run(type: JavaExec) {
main = 'com.sunova.bot.Launcher'
classpath = sourceSets.main.runtimeClasspath
}
I think your problem lies mostly in the definition of runQuasar which is not a run task and thus has no jvmArgs property but, if you don't need it for other reasons I'm unaware of, just do as in the Gradle template project (agent configuration) rather than defining runQuasar and declaring that run depends on it:
applicationDefaultJvmArgs = [
"-javaagent:${configurations.quasar.singleFile}" // =v, =d
]
If you need a separate runQuasar I think you'll need to declare it as a JavaExec task (have a look here).
I use thrift and it generates some source java files(interfaces) under build directory (build/generated-sources/thrift/<package name>/<class>) but under my src/main/java I have my classes which has the same package definition as in the generated java files and my classes also implements the interfaces generated by the thrift so how can I configure this in my build.gradle so it works on intelliJ as well as the build
plugins {
id "org.jruyi.thrift" version "0.3.1"
}
apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: "org.jruyi.thrift"
group 'com.hello'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.5
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.apache.thrift', name: 'libthrift', version:'0.9.3'
compile 'com.datastax.cassandra:cassandra-driver-core:3.0.0'
compile 'com.datastax.cassandra:cassandra-driver-mapping:3.0.0'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
compileThrift {
thriftExecutable "/usr/local/hello/bin/thrift"
sourceDir "src/main/thrift"
createGenFolder false
}
task thrift(type: Exec) {
commandLine '/usr/local/hello/bin/thrift'
}
compileJava {
dependsOn 'compileThrift'
The gradle build should work automatically.
To make it work on Intellij, try adding the following to your build.gradle.
idea.module.sourceDirs += file("$buildDir/generated-sources/thrift")
Don't forget to refresh your gradle projects.
I'm trying to add jacoco support to my gradle project, but when I add the jacoco plugin, it gives me an error.
Here is my gradle.build
task wrapper(type: Wrapper) { gradleVersion = '1.11' }
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'war'
apply plugin: 'eclipse'
apply plugin: 'eclipse-wtp'
apply plugin: 'application'
apply plugin: 'project-report'
apply plugin: 'jacoco'
eclipse {
classpath { downloadSources=true }
}
eclipse.classpath.file {
// Classpath entry for Eclipse which changes the order of classpathentries; otherwise no sources for 3rd party jars are shown
withXml { xml ->
def node = xml.asNode()
node.remove( node.find { it.#path == 'org.eclipse.jst.j2ee.internal.web.container' } )
node.appendNode( 'classpathentry', [ kind: 'con', path: 'org.eclipse.jst.j2ee.internal.web.container', exported: 'true'])
}
}
tasks.withType(Compile) { options.encoding = 'UTF-8' }
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
providedCompile 'javax.servlet:servlet-api:2.5'
runtime 'javax.servlet:jstl:1.1.2'
compile 'org.springframework.batch:spring-batch-core:2.2.5.RELEASE'
compile 'org.springframework:spring-webmvc:4.0.2.RELEASE'
compile 'org.springframework:spring-jdbc:4.0.2.RELEASE'
compile 'org.springframework:spring-orm:4.0.2.RELEASE'
compile 'org.springframework.data:spring-data-mongodb:1.4.0.RELEASE'
compile 'org.springframework.security:spring-security-web:3.2.1.RELEASE'
compile 'org.springframework.security:spring-security-config:3.2.1.RELEASE'
compile 'org.slf4j:slf4j-simple:1.6.1'
compile 'org.codehaus.groovy:groovy-all:2.2.0'
compile 'org.mongodb:mongo-java-driver:2.11.4'
compile 'c3p0:c3p0:0.9.1.2'
compile 'org.hibernate:hibernate-core:4.3.4.Final'
compile 'org.hibernate:hibernate-ehcache:4.3.4.Final'
compile 'org.hsqldb:hsqldb:2.0.0'
compile 'com.google.guava:guava:16.0'
compile 'commons-io:commons-io:2.4'
compile 'com.google.code.gson:gson:2.2.4'
compile 'org.codehaus.jackson:jackson-core-asl:1.9.13'
compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.13'
testCompile 'junit:junit:4.11'
testCompile 'commons-collections:commons-collections:3.2'
testCompile 'org.springframework:spring-test:4.0.2.RELEASE'
testCompile 'org.codehaus.groovy:groovy-all:2.2.0'
testCompile 'de.flapdoodle.embed:de.flapdoodle.embed.mongo:1.35'
testCompile 'org.springframework.batch:spring-batch-test:2.2.5.RELEASE'
compile localGroovy()
}
test {
testLogging { // Show that tests are run in the command-line output
events 'started', 'passed' }
exclude 'com/bambilon/All*'
exclude 'com/bambilon/**/slow/*'
}
and when I run refresh dependencies in Eclipse, it gives me this error:
Caused by: org.gradle.api.plugins.UnknownPluginException: Plugin with id 'jacoco' not found.
at org.gradle.api.internal.plugins.DefaultPluginRegistry.getTypeForId(DefaultPluginRegistry.java:86)
at org.gradle.api.internal.plugins.DefaultProjectsPluginContainer.getTypeForId(DefaultProjectsPluginContainer.java:102)
at org.gradle.api.internal.plugins.DefaultProjectsPluginContainer.apply(DefaultProjectsPluginContainer.java:37)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.applyPlugin(DefaultObjectConfigurationAction.java:101)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.access$200(DefaultObjectConfigurationAction.java:32)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction$3.run(DefaultObjectConfigurationAction.java:72)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.execute(DefaultObjectConfigurationAction.java:114)
at org.gradle.api.internal.project.AbstractProject.apply(AbstractProject.java:846)
at org.gradle.api.Project$apply.call(Unknown Source)
at org.gradle.api.internal.project.ProjectScript.apply(ProjectScript.groovy:34)
at org.gradle.api.Script$apply.callCurrent(Unknown Source)
Please help, thanks!
I am not quite sure which version introdueced jacoco plugin but with Gradle 2.x it for sure works. If you have a $buildDir/jacoco folder after running gradle build, you can be sure that it works. More information on http://www.gradle.org/docs/current/userguide/jacoco_plugin.html.
I have also got the same problem , I have set the gradle path in eclipse .It sloved for me.To set the path
Eclipse -Window->preference-type Gardle
Click on folder radio button , and set path to gradle folder located in your system.