How to build a jar without "-SNAPSHOT" in the name with Gradle? - java

Every time I run this command: gradle build it produces a my-program-1.0.0-SNAPSHOT.jar. Where do I control this? In the gradle.properties I have only the version nothing else. Even if I run gradle -Dversion=1.0.0 build it still creates a jar with SNAPSHOT in the name. How do I create a jar like this: my-program-1.0.0.jar?
I'm using spring boot.

Basically we have to change the project version in the gradle, To do so we have to use project api in gradle. you can refer https://docs.gradle.org/current/dsl/org.gradle.api.Project.html
One Solution I can suggest is:
Add version '1.0' in your build.gradle

Related

creating a jar and adding to another project as a library

I have java project build and executed successfully in IntelliJ using a gradle build tool. I want to create a jar file of this project and add it to the another project so that it can use this as a library. How can I create a jar and add it to another project?
Maven Publish Plugin
The Maven Publish Plugin gives you a task called publishToMavenLocal. If you run that task like so in the project that is the one you wish to publish:
./gradlew publishToMavenLocal
this will publish a jar that you can pull into another project, assuming you have your group, module and version setup properly.
The group property you can set in your build.gradle, version in the gradle.properties and the module will be the name of the module that is being built unless specified otherwise.
You can check in your ~/.m2 directory to see that they were published with the correct group, module, and version.
Then in your consuming module, you can specify mavenLocal() in your repositories dsl block, and declare your published jar that you want to consume just like any other dependency.

vscode java doesn't work with multi-project layout gradle project

java vscode doesn't work well with multi-project layout gradle project. I can simply reproduce this with the sample project generated by gradle init.
The error msg looks like some building task dependency issues: Cannot use Gradle object after build has finished
I've described the issue here https://github.com/redhat-developer/vscode-java/issues/1984
Just want see if anyone have met such issue before and any idea for a workaround?
I create a demo gradle project by Spring Initializr Java Support, with build.gradle and settings.gradle generated automatically, so when i run gradle init, it would throw > Task :init SKIPPED because settings file and build file already existed.
After i delete them manually, gradle init could be executed successfully and re-generate build.gradle and settings.gradle:
I've noticed the comment below your github issue:
This issue seems similar to another one I'm seeing with eclipse
buildship, so most likely it's an issue happening in latest gradle
version
And I'm using Gradle 7.0.2, there's no error shown. You may have a try.

Gradle tasks in Spring project

I found gradle tasks shown below in my Eclipse Java Spring project:
application
bootRun
build
assemble
bootBuildImage
...
build setup
documentation
help
ide
verification
What these tasks are coming from? Is it part of Gradle or Spring?
(1) You ask
What these tasks are coming from?
Gradle task come from 2 area: by Gradle itself and by Gradle plug-ins.
For example, at folder where has file build.gradle , (1a) when you run command
gradle bootRun
Spring Boot application when run, it usually run and return result at http://localhost:8080 (default). gradle bootRun run success by an plugin called Spring-boot-gradle-plugin declared inside build.gradle .
(1b) When you run
gradle wrapper
your project will add some folder and files, make your source code become portable, no need install Gradle at local PC when you share for your colleagues. gradle wrapper come from Gradle itself, not from third-party one.
(2) You ask
Is it part of Gradle or Spring?
(1b) from Gradle itself, (1a) is a plug-in made by Spring team.
Reference: https://github.com/spring-projects/spring-boot/tree/master/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin
They look to be gradle as assemble, build, buildDependencies are all standard irrespective of what you are building.

Installing Mockito using Gradle

I have installed Gradle by adding the path to it into the system variables. I am quite new to Java and this is the first time that I am trying to install an external library for it. On the Mockito web-page, they say that one can:
Declare a dependency on “mockito-core” library using your favorite
build system. With Gradle one can do:
repositories { jcenter() }
dependencies { testCompile "org.mockito:mockito-core:1.+" }
So I have no idea what it means. I changed the directory in cmd to the Gradle folder and tried to execute these commands, but that is not how one is supposed to do it. Can you give me a hand here?
You have to create a build.gradle file where you can insert the dependency. I recommend using an ide like eclipse or IntelliJ which can generate a gradle project for you so you don't have to do this manually. Just install the corresponding Gradle Plugin. This also makes sure you have a correct project structure.

How to find out, where a library is defined in IntelliJ?

Suppose IntelliJ says that my project uses some version of the library, like this:
How to find out where classes from this JAR are actually referenced?
There does not appear to be a way to display dependency tree as you can with maven.
You can run Gradle dependencies task to see the dependencies. To do it in Idea you can configure a Gradle Run configuration with task dependencies:

Categories

Resources