Initializing new Java projects with Gradle

I’ve used Maven for years for dependency management, but Gradle has better support for initializing a new Java source project compared to Maven. Although Maven has archetypes, I can never remember the syntax so usually just copy and paste a pom.xml file from somewhere else.

With Gralde you can ‘gradle init’ a new project and just follow the prompts:

> gradle init

Welcome to Gradle 8.1.1!

Here are the highlights of this release:
 - Stable configuration cache
 - Experimental Kotlin DSL assignment syntax
 - Building with Java 20

For more details see https://docs.gradle.org/8.1.1/release-notes.html

Starting a Gradle Daemon (subsequent builds will be faster)

Select type of project to generate:
  1: basic
  2: application
  3: library
  4: Gradle plugin
Enter selection (default: basic) [1..4] 2

Select implementation language:
  1: C++
  2: Groovy
  3: Java
  4: Kotlin
  5: Scala
  6: Swift
Enter selection (default: Java) [1..6] 3

Generate multiple subprojects for application? (default: no) [yes, no] n                          nolease enter 'yes' or 'no': 
Select build script DSL:
  1: Groovy
  2: Kotlin
Enter selection (default: Groovy) [1..2] 1

Select test framework:
  1: JUnit 4
  2: TestNG
  3: Spock
  4: JUnit Jupiter
Enter selection (default: JUnit Jupiter) [1..4] 1

Project name (default: java21playground): 
Source package (default: java21playground): 
Enter target version of Java (min. 7) (default: 21): 
Generate build using new APIs and behavior (some features may change in the next minor release)? (no


> Task :init
Get more help with your project: https://docs.gradle.org/8.1.1/samples/sample_building_java_applications.html

BUILD SUCCESSFUL in 1m 7s
2 actionable tasks: 2 executed

With Maven you add your dependencies to a <dependencies> block in your pom.xml, like

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.2</version>
        <scope>test</scope>
    </dependency>
</dependencies>

Dependencies with the default scope are considered part of your compile and runtime classpath, <scope>test</scope> indicates on the test classpath only.

With Gradle you do the same with your build.gradle properties file, in the dependencies section:

dependencies {
    testImplementation 'junit:junit:4.13.2'

    implementation 'com.google.guava:guava:31.1-jre'
}

implementation dependencies are for runtime, testimplementation are for test only.

28 years ago I posted a question to the comp.os.os2.setup.misc Usenet newsgroup about accessing multimedia content on an Enhanced CD. I still have the disk. It still works and plays (although not on all PCs)

I had a random thought: “What is the earliest trace of my own online activity that you easily find today?”. It’s hard to get search engines to return search results in date order, but Google Groups does. As well as hosting it’s own discussion groups, they also have an archive of most Usenet groups, including this one that I posted to on December 28th 1995:

There are several other posts in 1998 and 1999 asking questions about ‘Dynamic HTML’, or dHTML as it was known back then, while I was working on some dynamic webpage features with Javascript on IE5, which at the time I remember was the ‘new big thing’:

The interesting thing about the Enhanced CD I was asking about in 1995 is that I still have this CD:

On a modern desktop PC with an external USB DVD drive, the disk is only recognized as an audio CD. The audio plays fine, but it doesn’t recognize the Enhanced media content. The internal CD drive in my Mac G5 does see the additional content though – it mounts the disc as 2 volumes, 1 for the audio tracks and 1 for the data content:

The data volume has several movie files and screenshots:

What’s more interesting is the format of the movie files. Remember this CD was released in November 1995 – this was at the start of the era of ‘multimedia PCs’, Windows 95 had launched a couple of months earlier in August 1995. Look the format of the video files:

  • 320 x 240 pixels (!)
  • Mono 22kHz audio
  • 15 fps
  • 1 minute 37 seconds – this is only a fraction of the length of the audio single, it’s not even a complete video for the single

This same format is used for all the video clips, 24 in total:

It’s worth remembering the Windows 95 install CD shipped with a similarly low resolution, but full length, music video of Weezer’s Buddy Holly track, so this is a typical example of the technology at the time, although interesting why they decided to only include short 1 min clips and not full length music videos on the Stones CD.

It’s amazing looking back now when we’re able to stream 4k and 8k content and take it for granted, this was the start of consuming media content on a computer.