I am using gradle install and surprisingly my jar in /m2 repository not udpating.
Even though I deleted the folder and then did gradle install, I am unable to see the latest jar. The old jar is again getting created.
I did gradle install just now and see what happened (no errors) :
Below is my build.gradle
apply plugin: 'java-library'
apply plugin: 'eclipse'
apply plugin: 'maven'
group = 'bt'
version = '1.0'
repositories{
jcenter()
mavenCentral()
mavenLocal()
}
dependencies {
compile('bt:daoconfig:1.0')
compile('bt:common:1.0')
testCompile 'org.hsqldb:hsqldb:2.2.8'
testCompile 'org.powermock:powermock-mockito-release-full:1.6.4'
testCompile 'junit:junit:4.12'
testCompile 'org.springframework.boot:spring-boot-starter-test:1.5.2.RELEASE'
}
Kindly let me know what wrong i am doing?
thanks
I used gradle clean , then gradle install. It got updated. Thanks
I'm trying use Rxjava and I added it my gradle like so:
However, I'm not able to use it from within my src directory -- the autocomplete doesn't show any suggestions for Observable.
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'application'
sourceCompatibility = 1.8
version = '1.0'
repositories {
flatDir {
dirs 'lib'
}
}
sourceSets {
test {
java {
srcDir 'src/test/java'
}
}
}
dependencies {
testCompile 'org.hamcrest:hamcrest-core:1.3'
testCompile 'junit:junit:4.12'
testCompile 'org.assertj:assertj-core:1.7.1'
testCompile 'io.reactivex:rxjava:1.0.7'
testCompile 'io.reactivex:rxjava-math:1.0.0'
testCompile 'io.reactivex:rxjava-string:0.22.0'
compile 'io.reactivex.rxjava2:rxjava:2.2.0'
}
test {
testLogging {
events "passed", "skipped", "failed", "standardOut", "standardError"
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.2.1'
}
I want to be able to use the dependency from within my source directory.
Once you add a dependency to a build.gradle file you need to build the gradle project. This downloads all the dependencies and then the autocomplete will show the suggestion.
In Eclipse you can do the following:
Right Click on Project module-> Gradle->Refresh Gradle project
Otherwise from command prompt you can use the following command:
gradlew build
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 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 am trying to build and run this tutorial "Designing and Implementing RESTful Web Services with Spring" off-line, using a local repository for my dependencies. Here is my gradle.build file:
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
repositories {
flatDir { dirs 'lib' }
}
dependencies {
compile 'org.springframework:spring-core:4.0.6.RELEASE'
compile 'org.springframework:spring-beans:4.0.6.RELEASE'
compile 'org.springframework:spring-context:4.0.6.RELEASE'
compile 'org.springframework:spring-web:4.0.6.RELEASE'
compile 'org.springframework:spring-webmvc:4.0.6.RELEASE'
compile 'com.jayway.jsonpath:json-path:0.8.1'
compile 'org.slf4j:slf4j-api:1.7.5'
runtime 'org.slf4j:slf4j-jdk14:1.7.5'
// {!begin jackson}
runtime 'com.fasterxml.jackson.core:jackson-core:2.4.2'
runtime 'com.fasterxml.jackson.databind:jackson-databind:2.4.2'
runtime 'com.fasterxml.jackson.annotation:jackson-annotations:2.4.2'
// {!end jackson}
// {!begin jaxb}
runtime 'javax.xml.bind:jaxb-api:2.2.9'
// {!end jaxb}
// {!begin commons}
runtime 'org.apache.commons:commons-logging:1.1.1'
// {!end commons}
testCompile 'org.springframework:spring-test:4.0.6.RELEASE'
testCompile 'junit:junit:4.+'
testCompile "org.mockito:mockito-all:1.9.5"
testCompile "org.hamcrest:hamcrest-all:1.3"
testCompile 'javax.servlet:javax.servlet-api:3.0.1'
}
task wrapper(type: Wrapper) {
gradleVersion = '1.6'
}
Some of the tests fail with the following error:
java.lang.NoClassDefFoundError: Could not initialize class org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
This class is in the spring-web-4.0.6.RELEASE.jar, which is in the dependencies. What am I missing?