Can any body can tell me how can I do something like maven install -U (update dependencies) in gradle.
I have problem I have added new dependency to my build.gradle file
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
compile('org.springframework.boot:spring-boot-starter-web')
compile("org.springframework.boot:spring-boot-starter-security")
runtime('com.h2database:h2')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
New dependency is:
compile("org.springframework.boot:spring-boot-starter-security")
And during build or project synchronize my IntelliJ (version 14) is not even trying download this new dependency (I'm using gradle version 2.5)
In maven project IntelliJ had something like download maven dependencies.
But for Gradle I don't see anything like this. This is like my project looks like
And can any body tell me why I don't see any *.jar on project list like maven does?
Using IntelliJ
In the Gradle tool window, click refresh button. Here is the screen:
Using terminal
You must add to your build.gradle this line
apply plugin: 'idea'
And next if you are adding some dependencies and you want synchronize IntelliJ, you just use command
gradle idea
If any one have problem with finding Gradle Tool Window it's in:
View | Tool Windows | Gradle
Related
I'm trying to build tasks to allow me to specify my profile for my spring app using Gradle.
buildscript {
ext {
springBootVersion = '2.0.1.RELEASE'
}
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
}
}
plugins {
id "com.diffplug.gradle.spotless" version "3.10.0"
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'maven'
spotless {
java {
googleJavaFormat()
licenseHeaderFile 'habicus.license.java'
}
}
group = 'com.remindful'
version = '1.0.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-jersey')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-web-services')
compile('org.springframework.boot:spring-boot-starter-websocket')
compile('org.springframework.session:spring-session-core')
compile("com.h2database:h2")
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
compile group: 'com.google.guava', name: 'guava', version: '11.0.2'
testCompile 'junit:junit:4.12'
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '2.0.1.RELEASE'
}
// TODO: Add prod profile in application-properties
task prod {
run { systemProperty "spring.profiles.active", "prod" }
}
task dev {
run { systemProperty "spring.profiles.active", "dev" }
}
// To force debug on application boot, switch suspend to y
bootRun {
systemProperties System.properties
jvmArgs=["-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"]
}
tasks.bootRun.dependsOn build
bootRun.mustRunAfter dev
I have two questions:
1) Intellij highlight the tasks with yellow squiggly underline, so I'm wondering if the syntax here is wrong?
2) Do I use gradle-wrapper for something like this or just gradle? I'm trying to better understand the difference.
1) Intellij highlight the tasks with yellow squiggly underline, so I'm wondering if the syntax here is wrong?
Unfortunately, IntelliJ does not support gradle completely, for example, the ext block in the build script is not recognized correctly, so when accessing members defined throught the ext block, IntelliJ fails to resolve its definition & type.
So there's no need for panic when IntelliJ displays a yellow underline, you only need to take notice of the errors reported by the gradle command. If gradle build says OK, then everything is fine.
Meanwhile, IntelliJ is unable to resolve third-party plugins statically, therefore it is also unable to recognize tasks and Task classes added by these plugins. In this case, it will also show this yellowish underline complaining about something like cannot infer argument type.
The solution is to refresh all Gradle projects, by clicking the refresh button on the gradle panel, and if your build script is written correctly, these underlines will most probably vanish. This is because IntelliJ embedds with gradle using the Gradle Tooling API, and during the gradle sync process (fired by refresh all Gradle projects), third-party plugins got resolved and the whole project object model is built, so that IntelliJ would know that nothing is wrong with your tasks.
If gradle build fails, then the problem is with your own build script. On how to write gradle build scripts & tasks correctly, see Authoring Tasks - Gradle User Manual.
2) Do I use gradle-wrapper for something like this or just gradle? I'm trying to better understand the difference.
The Gradle wrapper is explained in the official userguide. To be brief, I would quote:
The Wrapper is a script that invokes a declared version of Gradle, downloading it beforehand if necessary.
So if you don't have a wrapper script in your project, you should execute gradle wrapper to generate one, and then commit it to your VCS. After that, wherever you previously execute gradle <task> in the command line, you can/should replace it with ./gradlew <task> (in *nix environment) or gradlew.bat <task> (in Windows).
The main difference between using the gradle command directly from the command line and the gradle wrapper script is, that the gradle wrapper script will download the gradle binary and uses it to execute gradle builds if no installed gradle binary is found, while using the the gradle command will only result in an error in such case.
Also, when someone else is using your project, he/she can simply clone the repo and run ./gradlew build (in *nix) or gradlew.bat build (in Windows) and your project will build fluently and successfully, regardless of whether he/she has previously installed a gradle distribution.
I want to print the last version of a dependency in gradle.
I added my dependency in this way :
compile 'test:test:+'
now I want to print the version of my dependency, because I want to know which version I'm using.
I'm using it in this way :
gradle dependencyInsight --configuration compile --dependency test:test
But my output is this :
+--- test:test:+ -> project : (*)
Is there anyway I can get the real version of my dependency and not the +?
Within app module's build.gradle I've imported Square's Moshi library as follows:
dependencies {
compile 'com.squareup.moshi:moshi:+'
}
Then I executed following command in terminal:
./gradlew app:dependencyInsight --configuration compile --dependency com.squareup.moshi:moshi
Here's the output that I've received:
All easy, open hierarchy of view Project and see External Libraries
If you want to check the overview for all your dependencies, you can check with this command -
Solution 1-
./gradlew app:dependencies
Or
Solution 2-
If you want to check for any specific dependency.you can use gradles' build-in 'dependencyInsight : -
gradle dependencyInsight --configuration compile --dependency compile 'test:test:+'
or
Solution 3-
You can check your project .idea folder
inside your project -> .idea/libraries
there also you can see the final version of dependencies used.
You can do the following:
Use the configuration that contains your jar file
Filter for the the jar file's name
Print the results
This will print the full path as well as the version. You can extract just the jar name if needed.
task printPmdVersion << {
FileTree pmdJar = zipTree(configurations.pmd.filter {
dep -> dep.name.contains("pmd-core")
}.singleFile)
println pmdJar
}
Example of output:
ZIP '/home/user/java/gradle_user_home/caches/modules-2/files-2.1/net.sourceforge.pmd/pmd-core/5.4.1/28715c2f768b58759bb5b373365997c30ac35899/pmd-core-5.4.1.jar'
Once you have added your dependency as "compile 'test:test:+'" build the project.
Then within the "Project" folder structure hierarchy find that dependency within "External Libraries" at the bottommost of folder structure , it will along with its version there. Use that version with your dependency and re-sync/build project again.
It's not a best practice use the '+' sign to always use the latest library version because you could not be able to have a repeatable build if you need one.
I mean, if you have to checkout your previous version of your APK from your Source Control Management system (e.g. Git) that you know it works fine, if you compile today (new library version could have been release)... maybe your old friend APK that was working fine... now it doesn't work fine like your latest one.
That said I suggest you using a gradle plugin like that:
https://github.com/ben-manes/gradle-versions-plugin
You will install in your build.gradle at project level like that:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply plugin: 'com.github.ben-manes.versions'
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.github.ben-manes:gradle-versions-plugin:0.17.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And you'll find a new gradle task named dependencyUpdate that if you lunch it it will report you all your library versions compared with the latest ones:
------------------------------------------------------------
: Project Dependency Updates (report to plain text file)
------------------------------------------------------------
The following dependencies are using the latest milestone version:
- com.github.ben-manes:gradle-versions-plugin:0.17.0
- junit:junit:4.12
The following dependencies have later milestone versions:
- com.android.support:appcompat-v7 [26.1.0 -> 27.0.2]
- com.android.support.constraint:constraint-layout [1.0.2 -> 1.1.0-beta5]
- com.android.support.test.espresso:espresso-core [3.0.1 -> 3.0.2-alpha1]
- com.android.tools.build:gradle [3.0.1 -> 3.2.0-alpha03]
- org.jacoco:org.jacoco.agent [0.7.4.201502262128 -> 0.8.0]
- org.jacoco:org.jacoco.ant [0.7.4.201502262128 -> 0.8.0]
- com.android.support.test:runner [1.0.1 -> 1.0.2-alpha1]
I am using gradle in Eclipse, and my gradle.build is pretty basic (adds java plugin, sets repos and not alot more) and I am building a JavaFX program. All my code compiles and run correctly with my build scripts with 0 errors.
I am just annoyed at the fact when I add the JavaFX SDK to my build path libraries, I can see my project has it listed. When I sync my project with Gradle, gradle removes this SDK from my classpath file.
What do I need to add to my build script to stop this from happening and gradle to normally inject it into my .classpath as it does with anything else I add?
Cheers,
P.S. I'm really new to gradle and groovy and this is my first 'project' working with it. Apart from this one annoyance, it's been smooth going.
Solved this issue: completely forgot classpath is todo witth eclipse and not java/gradle.
Adding:
apply plugin: 'eclipse'
eclipse {
classpath.containers 'org.eclipse.fx.ide.jdt.core.JAVAFX_CONTAINER'
}
to my gradle.build file solved this issue.
I actually found a solution for this via https://groups.google.com/forum/#!topic/javafxports/Fn92C5ysC60 'android forum' while looking up how I could automate the building of eclipse.
Cheers if anyone looked into this.
As a side note, as I was confused about this first: A JavaFX project is no different from a Java project and you don't need to specify the fact you're using JavaFX to your ide to be able to execute JavaFX code. So I was confused why my IDE had a 'Start a new JavaFX project' and 'Start a new Gradle Project' but no JavaFX/Gradle project.
You don't 'need' a JavaFX plugin like my project originally had either.
To solve your problem, you need JavaFX-Gradle-plugin, it's a plugin that enable JavaFX support on Gradle project.
This is the link of plugin: https://github.com/FibreFoX/javafx-gradle-plugin, where you can find all infos and example...
All of you need is to start a new Gradle project, then add to your file build.gradle this code:
buildscript {
dependencies {
classpath group: 'de.dynamicfiles.projects.gradle.plugins', name: 'javafx-gradle-plugin', version: '8.8.2'
}
repositories {
mavenLocal()
mavenCentral()
}
}
apply plugin: 'java'
repositories {
mavenLocal()
mavenCentral()
}
dependencies{
// put here your project dependencies
}
apply plugin: 'javafx-gradle-plugin'
// these values are the examples and defaults
// you won't need them all
// configure javafx-gradle-plugin
jfx {
// minimal requirement for jfxJar-task
mainClass = 'YOUR.MAIN.CLASS'
// minimal requirement for jfxNative-task
vendor = 'YOUR NAME OR COMPANY'
// some optional task
jfxAppOutputDir = 'build'
jfxMainAppJarName = 'YOUR APPLICATION NAME.jar'
manifestAttributes = [
"Specification-Version": 1.0,
"Implementation-Version": 1,
"Built-By": "YOUR NAME OR COMPANY",
]
// for a full list of available settings, look the class "JavaFXGradlePluginExtension" on plugin project
}
This is the only plugin that I've found for use JavaFX with Gradle.
I'm working with Eclipse on project with same problem, and I've solved it a few days ago.
Hope this help,
BoGnY
I have a project that I use gradle to build. Before I installed Gradle Eclipse plugin, I was able to see the gradle build folder in Eclipse. But after installing the plugin (Buildship) and creating and building a new Gradle project, I am no longer able to see the build folder in Project Explorer or Package Explorer or Navigator. I am able to see the build folder and the jar file from Windows Explorer. I tried to change the settings from Customize View..., but it didn't solve the issue. Can someone please let me know how to let the build folder show up ? Thanks.
This is the build.gradle:
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'application'
mainClassName = 'com.ii.mainClass'
repositories {
mavenCentral()
}
sourceCompatibility = 1.7
targetCompatibility = 1.7
dependencies {
compile 'com.fasterxml.jackson.core:jackson-annotations:2.6.1'
compile 'com.fasterxml.jackson.core:jackson-core:2.6.1'
compile 'com.fasterxml.jackson.core:jackson-databind:2.6.1'
compile 'org.springframework:spring-beans:4.2.0.RELEASE'
compile 'org.springframework:spring-context:4.2.0.RELEASE'
compile 'org.springframework:spring-core:4.2.0.RELEASE'
compile 'org.springframework:spring-expression:4.2.0.RELEASE'
compile 'org.springframework.xd:spring-xd-tuple:1.0.4.RELEASE'
}
I found the solution in a topic on the Gradle forum (https://discuss.gradle.org/t/setting-eclipse-native-library-location/11075/2).
The plugin installs a resource filter with an exclude pattern, which you can manually remove in the project's properties (Resource -> Resource Filters).
You can disable filter through customize filter in project explorer options, and uncheck the gradle build option in it.
Select the project and then select the project menu as given in the below image.
screenshot
And then uncheck the 'Grale build folder' and then you can see the build folder as shown in below image.
screenshot
I want to try out Vaadin 7 with java 8, gradle 2.1, and IntelliJ 13.1.5 on Mac OSX. I installed gradle with brew. Here's what I've done so far
I created a project using the gradle wizard in Intellij
I set up tomcat like this Creating a Project with Intellij IDEA vaadin tutorial.
I've added the vaadin-gradle-plugin to my build.gradle file.
I hit the gradle refresh button
I ran vaadinCreateProject in the intellij gradle plugin menu
I made sure my JAVA_HOME and GRADLE_HOME point to correct locations
Everything works correctly with gradle commands, I ran vaadinRun and navigated http://localhost://8080 and saw the hello world. But IntelliJ has all identifiers highlighted red with "cannot resolve symbol". I've tried every form of recompiling and clearing caches.
How can I get Intellij recognize the code?
My gradle.build file.
apply plugin: 'java'
apply from: 'http://plugins.jasoft.fi/vaadin.plugin'
sourceCompatibility = 1.5
version = '1.0'
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
}
The Vaadin Gradle plugin injects the Vaadin dependencies at runtime which Intellij's JetGradle plugin does not pick up for some reason.
What you can do instead is use the Gradle idea plugin (apply plugin: 'idea' in your build.gradle) and run the idea task. After that import the project into Intellij and all dependencies should be on the classpath.
Whenever you add a dependency you need to run the idea task again so the classpath is updated.
According to JetBrains,
Vaadin plugin requires Gradle 3.0+
// Vaadin plugin requires Gradle 3.0+
task wrapper(type: Wrapper) {
gradleVersion = '3.0'
}
I am not sure your project will be OK with that spoon of groovy, but without it it shouldn't work.