Gradle install not updating the jar - java

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

Related

IntelliJ IDEA 2016.3.4 gradle how to run the java project

how can I run my gradle project? Its a GUI application. I just want to run it so I can test it. Created a gradle project, copied my src file in and marked it as a source file (blue file). Now when I click run, the project runs all the gradle tasks but my application does not start. Here is my build.gradle file:
group '1'
version '1.0-SNAPSHOT'
apply plugin: 'groovy'
apply plugin: 'java'
apply plugin: 'application'
mainClassName = 'Main'
version = '1'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
jar {
baseName = 'JavaWinApp'
from files(sourceSets.main.output.classesDir)
from files(sourceSets.main.output.resourcesDir)
from { configurations.compile.collect { zipTree(it) } }
manifest {
attributes 'Implementation-Title': 'JavaWinApp'
attributes 'Implementation-Version': version
attributes 'Main-Class': 'Main'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'org.codehaus.groovy:groovy-all:2.3.11'
testCompile group: 'junit', name: 'junit', version: '4.11'
compile 'com.intellij:forms_rt:6.0.5'
}
Can you see anything blatantly obvious that I should change or can you give me any pointers?
Please let me know if you require any other information and I will happily supply it. I am an utter noob with this. My only exposure to gradle is through Android Studio, there all just runs fine. Looks like I'm missing something obvious, but cannot seem to find it.
Thank you in advance
The gradle application plugin should add a run task to your build, that will start your application. To execute this task you will need to create a run configuration in IntelliJ for this task. See this documentation on how to create a gradle run/debug configuration.

Is there any way of making IntelliJ IDEA recognizing Dagger 2 generated classes in a Java project?

Context
I have started a personal project in java with Gradle as the build system and I want to use Dagger 2 as a DI. The main reason of doing that is to get used to that library and be able to use it easily in bigger projects.
What have I tried
I've managed to make the Google sample runs on IntelliJ IDEA
Problem
IntelliJ IDEA keeps telling me that it cannot resolve the generated class (in this case DaggerCoffeeApp_Coffee). It's a bit annoying not to know if the written code is correct (specially when you are learning to use Dagger 2).
All java classes are the same as the Google sample. Here is my build.gradle file:
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile 'com.google.dagger:dagger:2.0.1'
compile 'com.google.dagger:dagger-compiler:2.0.1'
}
Question
Is there any way to make IntelliJ IDEA recognize DaggerCoffeeApp_Coffee as a generated class (and so make it possible to go to its implementation by `ctrl + left click)?
Simplest way I found:
Add idea plugin and add Dagger2 dependency like below:
plugins {
id "net.ltgt.apt" version "0.10"
}
apply plugin: 'java'
apply plugin: 'idea'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile 'com.google.dagger:dagger:2.11'
apt 'com.google.dagger:dagger-compiler:2.11'
}
Turn on Annotation Processing for IntelliJ: Go to Settings and search for Annotation Processors, check Enable annotation processing like below image:
Finally I made it!
I had to add the apt and the idea plugin so right now my build.gradle file look like this:
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "net.ltgt.gradle:gradle-apt-plugin:0.4"
}
}
apply plugin: "net.ltgt.apt"
apply plugin: 'java'
apply plugin: 'idea'
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile 'com.google.dagger:dagger:2.0.1'
apt 'com.google.dagger:dagger-compiler:2.0.1'
}
you must manually enable the annotation processing in IntelliJ.
From: Settings --> Build, Execution, Deployment --> Compiler --> Annotation Processors --> Enable annotation processing and Obtain processors from project classpath
then rebuild the project and you will find the generated classes in the project.
Please note that I have used this solution in a (java) android project.
I'm using version 2017.3.3 of IntelliJ IDEA, version 0.14 of the net.ltgt.apt plugin and version 2.14.1 of Dagger and as well as applying the idea plugin in the build.gradle file (as in Pelocho's answer) I found I also had to tell IntelliJ where it can find the sources generated by Dagger, as follows:
apply plugin: 'idea'
idea {
module {
sourceDirs += file("$buildDir/generated/source/apt/main")
testSourceDirs += file("$buildDir/generated/source/apt/test")
}
}
This is what I had to do in order to get Idea to work with Dagger2 and gradle.
Turn on annotation processing as shown in the answers above.
Add the following to the build.gradle file in order for Idea to see the generated classes as sources.
sourceDirs += file("$projectDir/out/production/classes/generated/")
Here's the full listing of my build.gradle
plugins {
id 'java'
id 'idea'
id "net.ltgt.apt" version "0.10"
}
idea {
module {
sourceDirs += file("$projectDir/out/production/classes/generated/")
}
}
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.dagger:dagger:2.16'
apt 'com.google.dagger:dagger-compiler:2.16'
}
sourceCompatibility = 1.8
Also, I had to add the following gradle task (to my build.gradle file) to clear out my out directory. When I moved some files around and Dagger2 regenerated the source files, the out directory wasn't being cleared out :(. I also included this task in my run configuration, so that it gets triggered before I rebuild my project.
task clearOutFolder(type: Delete) {
delete 'out'
}
Here's the solution that worked for me:
File -> Project Structure -> (select your project under list of modules) -> Open 'Dependencies' tab
Then, click on green '+' sign, select 'JARs or directory' and select 'build/classes/main' folder.
Another solution would be to link folder with build class files using 'dependencies' block inside build.gradle:
https://stackoverflow.com/a/22769015/5761849
Using IntelliJ IDEA 2019.1 and Gradle 5.4.1, this seems to be enough:
plugins {
id 'java'
}
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testImplementation group: 'junit', name: 'junit', version: '4.12'
implementation 'com.google.dagger:dagger:2.23.1'
annotationProcessor 'com.google.dagger:dagger-compiler:2.23.1'
}
I don't know the minimal versions for which this solution works, though.
I had a similar problem, I could not find out the cause for a long time.
Just launched and the result surprised me.
Intellij Idea 2018.3.6 -
build.gradle:
plugins {
id "java"
}
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile 'com.google.dagger:dagger:2.11'
apt 'com.google.dagger:dagger-compiler:2.11'
}
The following worked for me on IntelliJ 2021.3.3 (UE)
plugins {
id 'java'
id 'idea'
id("com.github.johnrengelman.shadow") version "7.1.2"
}
idea {
module {
sourceDirs += file("$projectDir/build/generated/sources/annotationProcessor/java/main")
testSourceDirs += file("$projectDir/build/generated/sources/annotationProcessor/java/test")
}
}
group 'com.codigomorsa'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
annotationProcessor 'com.google.dagger:dagger-compiler:2.44'
implementation 'com.google.code.gson:gson:2.9.1'
implementation 'com.google.dagger:dagger:2.44'
testAnnotationProcessor 'com.google.dagger:dagger-compiler:2.44'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0'
}
test {
useJUnitPlatform()
}

Failed to apply plugin [id 'spring-boot']

I am trying to use Spring boot in my gradle project. But when I try to clean build, it gives the following error (only relevant stacktrace):
Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin [id 'spring-boot']
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.applyPlugin(DefaultObjectConfigurationAction.java:117)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.access$200(DefaultObjectConfigurationAction.java:36)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction$3.run(DefaultObjectConfigurationAction.java:80)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.execute(DefaultObjectConfigurationAction.java:131)
at org.gradle.api.internal.project.AbstractPluginAware.apply(AbstractPluginAware.java:37)
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)
at build_2o7juvjo3110jmss6k1iqcfrir.run(/Users/AlmasBarday/bos-api/build.gradle:13)
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:52)
... 57 more
Caused by: org.gradle.api.plugins.UnknownPluginException: Plugin with id 'spring-boot' not found.
at org.gradle.api.internal.plugins.DefaultPluginRegistry.getTypeForId(DefaultPluginRegistry.java:91)
at org.gradle.api.internal.plugins.DefaultPluginContainer.getTypeForId(DefaultPluginContainer.java:183)
at org.gradle.api.internal.plugins.DefaultPluginContainer.apply(DefaultPluginContainer.java:103)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.applyPlugin(DefaultObjectConfigurationAction.java:115)
My build.gradle has the following:
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'spring-boot'
dependencies {
compile 'org.slf4j:slf4j-api:1.7.5'
compile 'net.sourceforge.jexcelapi:jxl:2.6.12'
compile 'com.qas:proweb:1.0.0'
compile "org.springframework:spring-beans:$springVersion"
compile "org.springframework:spring-jdbc:$springVersion"
compile "org.springframework:spring-web:$springVersion"
compile "org.springframework.boot:spring-boot-starter-web:1.2.7.RELEASE"
testCompile 'junit:junit:4.11'
}
I searched the internet and tried solutions posted to similar problems, but nothing seems to work. Also, I am able to build another gradle-springboot project without any problems.
Any help appreciated.
You've forgot to configure you buildscript, by adding it's dependencies part. You can do it, by addin this to your build.script:
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.5.RELEASE")
}
}
Here you're configuring your buildscript dependencies, to make it possible for Gradle to apply the plugin. But that does not mean, that you can delete dependency for you sources. They are still use to be there, like you already have:
dependencies {
...
compile "org.springframework:spring-beans:$springVersion"
compile "org.springframework:spring-jdbc:$springVersion"
compile "org.springframework:spring-web:$springVersion"
compile "org.springframework.boot:spring-boot-starter-web:1.2.7.RELEASE"
}
plugins { id "org.springframework.boot" version "2.0.1.RELEASE" }
The above script should also be added to build.gradle at the top level to make it work.

Gradle with IntelliJ not loading PostgreSQL JDBC as a dependency

I am trying to setup IntelliJ alongwith Gradle and JOOQ for my next project. As of now, this is how my Gradle file looks like:
apply plugin: 'java'
apply plugin: 'jooq'
sourceCompatibility = 1.5
version = '1.0'
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
}
dependencies {
compile 'org.jooq:jooq:3.1.0'
compile 'com.google.guava:guava:14.0'
compile 'postgresql:postgresql:9.1-901-1.jdbc4'
}
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'postgresql:postgresql:9.1-901-1.jdbc4'
classpath 'com.github.ben-manes:gradle-jooq-plugin:0.5'
}
}
jooq {
... snip ...
}
And this is how my external dependencies (in IntelliJ) show up:
.
Somehow, Gradle is downloading and IntelliJ is recognizing the jooq and guava as part of my dependencies, but postgresql does not show up. So, while doing this works (using Guava, a dependency loaded from Gradle):
List<String> stringList = Lists.newArrayList();
This fails with a ClassNotFoundException:
Class.forName("org.postgresql.Driver").newInstance();
While doing a ./gradlew build, I have seen gradle output the fact that it did download thr postgresql-9.1-901 jar from Maven Central, but I don't know where it keeps it. Any help is greatly appreciated.
Apparently, I really need to RTFM. I hadn't refreshed the dependencies from the Gradle tool window in IntelliJ after making changes to the Gradle script. Got it from here: https://www.jetbrains.com/idea/webhelp/synchronizing-changes-in-gradle-project-and-intellij-idea-project.html

Plugin with id 'jacoco' not found + Gradle

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.

Categories

Resources