Gradle build doesn't generate jar

gradle build command
gradle tutorial
gradle download
gradle-version
gradle not downloading dependencies intellij
gradle build not downloading dependencies
gradle version command
gradle wrapper

I would like to build my project as a jar file which only contains my code. This project jar is used as a library to other java project.

Here is my build.gradle:

plugins {
    id 'java'
}

group 'com.my.lib'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

task sourcesJar(type: Jar) {
    archiveClassifier = 'sources'
    from sourceSets.main.allJava
}


dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

After I build the project (I am using IntelliJ, I clicked "Build" ==> "Rebuild project"). IntelliJ told me build successfully But I don't see any jar created. Why?

18:30:18: Executing tasks ':classes :testClasses'...

> Task :compileJava
> Task :processResources NO-SOURCE
> Task :classes
> Task :compileTestJava
> Task :processTestResources NO-SOURCE
> Task :testClasses

BUILD SUCCESSFUL in 0s
2 actionable tasks: 2 executed
18:30:18: Tasks execution finished ':classes :testClasses'.

The "Build Project" form IntelliJ IDEA will compile your code for usage in the IDE, it is not directly tied to the build lifecycle task of Gradle.

For Gradle to build the JAR, you need to run ./gradlew assemble, which will have the expected outcome. Note that this will not run tests or static analysis. If you want that to run as well, you can use ./gradlew build.

Both of these Gradle tasks can be executed from the Gradle tool window in IntelliJ IDEA.

Creating New Gradle Builds, The command should show "BUILD SUCCESSFUL" and generate the following "​empty" project. If it doesn't, please ensure that Gradle is installed properly, and  You run a Gradle build using the gradle command. The gradle command looks for a file called build.gradle in the current directory. We call this build.gradle file a build script, although strictly speaking it is a build configuration script, as we will see later. The build script defines a project and its tasks.


I figured out that even I have those settings, when I choose Build->Build project, Intellij still not run Gradle build that's why in my original question there is no "sourceJar" showing. I have to open "Gradle tool" window, click on that little elephant icon to run gradle task. Then, type "Gradle build", it then run the source Jar task.

Improving the Performance of Gradle Builds, Every plugin and script that you apply to a project adds to the overall configuration time. Some plugins have a greater impact than others. That doesn't mean you  Now if you run gradle build, Gradle should resolve the Joda Time dependency from the Maven Central repository and the build will succeed. Build your project with Gradle Wrapper The Gradle Wrapper is the preferred way of starting a Gradle build. It consists of a batch script for Windows and a shell script for OS X and Linux.


Gradle build doesn't work if the plugin isn't in the local repository , Describe the bug When running any Gradle task, the build fails Expected behavior Gradle build should work Actual behavior It doesn't work. If your project builds successfully some time it may be gradle download problem with a current proxy. Gradle has it's own dependency management system similar to maven. I think parts of the gradle publish plugin are backed by maven in some way (not verified). Regardless you shouldn't have to worry about that level of depth, gradle will handle it.


Getting Started, These scripts allow you to run a Gradle build At this stage, gradle doesn't know enough about  Without cleaning the test results (using cleanTest task) or the build entirely (by running the clean task) you'll get stuck with the failed tests results which will cause your build to fail. Similar side effects can happen also with resources/classes removed from the sources but remained in the build folder that was not cleaned.


3. Build Hooks - Gradle Beyond the Basics [Book], But your ability to customize a Gradle build doesn't end with plug-ins. Gradle offers you the ability to modify the execution of that program by hooking a variety of  From mobile apps to microservices, from small startups to big enterprises, Gradle helps teams build, automate and deliver better software, faster. Write in Java, C++, Python or your language of choice. Package for deployment on any platform. Go monorepo or multi-repo. And rely on Gradle's


How to decrease your Gradle build time by 65%?, The less time you spend watching gradle build your project, the more you Any more increase in the heap size doesn't affect the build timing  When you open the Build Analyzer, the window shows you a breakdown of the plugins that contributed the most to your build’s duration, as well as a tree to help you navigate other useful data about your build, as shown in figure 1. It’s important to note that the Build Analyzer doesn't display data for all tasks in your build.