gradle Difference between jar and assemble task - gradle

what is the difference between assemble and jar task of java plugin in gradle?
I tried executing them with a sample Hello world project they both seems to do the same job.

Since jar is a single task, which assembles a jar-archive for current project, assemble is, according to documentation:
assemble All archive tasks in the project, including jar. Some plugins add additional archive tasks to the project. Task Assembles all the archives in the project.
It is build-cycle task, which execute all the task of this build-cycle phase. Like a check task, which runs all test and verification task, assemble Runs all task, which essemble some artifacts. And the 'jar' could be not the only such a task in the project, some plugins could add them too.

Related

Gradle: why assemble task is getting skipped saying it has no actions?

I am trying to do gradle build of spring boot application , when I run the clean build command locally, it internally call few other tasks in which "assemble" is one task, locally it is creating the jars under build/libs folder.
But when this runs on jenkins it says skipping task "assemble" as it has no actions and no jars are produced.

Difference between gradle build and gradle bootJar?

What is the difference between "gradle build" and "gradle bootJar"? Why would I use bootJar if I can still create the artifact using build?
build is a lifecycle task contributed by the Base Plugin. It is
Intended to build everything, including running all tests, producing the production artifacts and generating documentation. You will probably rarely attach concrete tasks directly to build as assemble and check are typically more appropriate.
bootJar on the other hand is a specific task added by Spring Boot Gradle plugin that, when the java plugin is present, attaches itself to the assemble lifecycle task.
The assemble task is automatically configured to depend upon the bootJar task so running assemble (or build) will also run the bootJar task.
(Packaging Executable Jars)
You want to use bootJar if you're only interested in building the executable jar and not interested in executing tests, code coverage, static code analysis or whatever is attached to the check lifecycle task.

How to list all Gradle projects in multi-project build

I have a project with several Gradle modules (I think Gradle just calls these sub-projects). Basically I have a bunch of projects/modules listed in settings.gradle. Is there a Gradle command to print each one (either name or ideally a supplied label/description)
Unspectacularly, that task is simply called "projects", and (if you are using the Gradle wrapper) ./gradlew projects executed at the root project lists all sub-projects.
In general, if you are looking for a task, your chances are good that you can guess its name from the task list shown by ./gradlew tasks.

Gradle > How to deploy a JAR with only its needed dependencies jars to a remote computer

I am a new Gradle user. My task is to build a Gradle based project and then copy the final jar along with its dependencies jars to a remote host.
My approach is to do a local build, and then copy dependencies jars from caches to a local directory with a gradle task, which looks like:
task copyDependencies(type: Copy) {
from configurations.runtime
into "build/libs/deps"
}
But this task copies all the dependencies, say including transitive dependencies to the target directory; moreover, the runtime group include compile dependencies by default. So I would like to exclude the transitive dependencies, which takes great amount of space and the compile time dependencies jars. Is there any solution?
At last I plan to copy the generated jar and dependencies jars to a remote host by means of ssh, but I guess there should a way to directly finish this by means of a gradle task
Faithfully hope someone can give some useful hint
you need to create a fatJar, you can find an example on how to do it here:
Building a uberjar with Gradle
For copying to a remote directory you can get an example using an ant task here :How to copy directory via scp within gradle task?
Or alternatively you can use an Exec task which will an external tool (scp for example) : https://docs.gradle.org/current/dsl/org.gradle.api.tasks.Exec.html
Hope this helps

Declare tests to run without compiling sources

Consider such a situation: there's a big project, which takes tremendous time to compile and I'm having it's resulting artifacts as separate files (jar).
I want to run the unit tests on this project without compiling and jar-ing project itself, so I need to remove dependency on compileJava task, but this task is not in the dependsOn list of test task.
dependsOn property of test task contains only some [file collection] and if I'm printing this FileCollection.files, I'm getting the list of files and directories, which include .../build/classes/main. I think, after removing this entry, I'll get success in removing dependency on compileJava (as I understood, .../build/classes/main is just the result of running compileJava and that's why compileJava appeared). But I just don't understand, how to remove this entry.
By the way, in this case there's no problem of adding this jar to classpath, so that's not an issue.
I'm using Gradle 1.8.
Thanks.
compileJava will be up-to-date if nothing has changed, and jar isn't depended upon by test. If you nevertheless want to add the ability to run tests against a downloaded Jar, declare another Test task. (Reconfiguring test.classpath should work as well, but seems less desirable.)

Resources