Example of a single project build

I am having a heck of a time getting a fresh single-project build working with Gradle. I am only a part-time Java dev, and I have mostly worked with multi-project builds. I’m not expert, but I can work with them.

The other day I was struggling to bootstrap a single project build (Gradle 7), using only a single build.gradle at the project level, and a single src folder at the root level with my code.

What am I missing? It seems to be unable to fetch the required dependencies. All the examples I see in the docs are for multi-project builds.

Multi- or Singleproject do not really make any difference.
A Singleproject build is just a Multiproject build with only one project, nothing more.

What you might have done wrong is hard to guess, as you shared no information at all.
Neither what you have in your build script, nor the concrete error message you get when you do what, nor a build --scan.

Fair point! I was following this guide: https://spring.io/guides/gs/gradle
With a structure of:

β”œβ”€β”€ gradle
β”‚   └── wrapper
β”‚       β”œβ”€β”€ gradle-wrapper.jar
β”‚       └── gradle-wrapper.properties
β”œβ”€β”€ gradle.build
β”œβ”€β”€ gradlew
β”œβ”€β”€ gradlew.bat
β”œβ”€β”€ settings.gradle
└── thing
    └── src
        └── main
            └── java
                └── hello
                    β”œβ”€β”€ Greeter.java
                    └── HelloWorld.java

And a gradle.build of:

    id 'java'

repositories {

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    implementation "joda-time:joda-time:2.2"
    testImplementation "junit:junit:4.12"

jar {
    archiveBaseName = 'gs-gradle'
    archiveVersion =  '0.1.0'

But when I run gradlew build, I get:

No dependencies

A web-based, searchable dependency report is available by adding the --scan option.

1 actionable task: 1 executed

With no actual build folder created. What did I miss?

gradle.build is not a file Gradle cares about.
=> you have no build script
=> you end up effectively with an empty build script

What you meant is build.gradle.

But I highly recommend build.gradle.kts. The Kotlin DSL by now is the default DSL, you immediately get type-safe build scripts, actually helpful error messages if you mess up the syntax, and amazingly better IDE support if you use a good IDE like IntelliJ IDEA or Android Studio.

Oh my goodness, what a dumb mistake. :person_facepalming:
Haha thanks for correcting me here @Vampire

And good suggestion re: Kotlin, I am changing to that! Groovy begone!

1 Like