Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Gradle wrapper per exercise #2657

Merged
merged 8 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,4 @@ resources/exercise-template/bin
resources/exercise-template/.classpath
resources/exercise-template/.project
resources/exercise-template/.settings/
resources/exercise-template/gradle/
resources/exercise-template/gradlew
resources/exercise-template/gradlew.bat
*.class
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,19 @@ After making changes to one or more exercises, make sure that they pass all vali
#### Check whether the reference implementation passes the tests

```sh
gradle test
./gradlew test
```

#### Check whether the reference implementation passes the Checkstyle validations

```sh
gradle check
./gradlew check
```

#### Check whether the starter implementation is able to compile with the tests

```sh
gradle compileStarterTestJava
./gradlew compileStarterTestJava
```

### Open a Pull Request
Expand Down
271 changes: 25 additions & 246 deletions docs/INSTALLATION.md
Original file line number Diff line number Diff line change
@@ -1,261 +1,40 @@
# Installing Java

In addition to the exercism CLI and your favorite text editor, practicing with Exercism exercises in Java requires:
In addition to the Exercism CLI and your favorite text editor,
practicing with Exercism exercises in Java requires the **Java Development Kit** (JDK).
The JDK includes both a Java Runtime _and_ development tools (most notably, the Java compiler).

- the **Java Development Kit** (JDK) — which includes both a Java Runtime _and_ development tools (most notably, the Java compiler); and
- **Gradle** — a build tool specifically for Java projects.
There are many flavors of the JDK nowadays, some of which are open-source.
Here at Exercism we recommend using [Eclipse Temurin by Adoptium][adoptium].

Choose your operating system:
## Supported Java versions

- [Windows](#windows)
- [macOS](#macos)
- [Linux](#linux)
Exercism's Java track supports Java 21 LTS and earlier.

... or ...
## Installing Eclipse Temurin

- if you prefer to not use a package manager, you can [install manually](#install-manually).
To install Eclipse Temurin on your system, head on over to their excellent [installation instructions][adoptium-installation-guide].
Here you will find instructions on how to install the JDK using your favorite package manager,
and it also contains links to downloadable installers for all major operating systems.

Optionally, you can also use a [Java IDE](#java-ides).

## Windows

Open an administrative command prompt. (If you need assistance opening an administrative prompt, see [open an elevated prompt in Windows 8+](http://www.howtogeek.com/194041/how-to-open-the-command-prompt-as-administrator-in-windows-8.1/) (or [Windows 7](http://www.howtogeek.com/howto/windows-vista/run-a-command-as-administrator-from-the-windows-vista-run-box/))).

1. If you have not installed Chocolatey, do so now:

```batchfile
C:\Windows\system32> @powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin
```

2. Install the JDK:

```batchfile
C:\Windows\system32> choco install temurin21
...
C:\Windows\system32> refreshenv
...
```

3. Install Gradle:

```batchfile
C:\Windows\system32>choco install gradle
...
```

We recommend closing the administrative command prompt and opening a new command prompt.
You do not require administrator privileges to practice Exercism exercises.

You now are ready to get started with the Java track of Exercism!

To get started, see "[Running the Tests](https://exercism.org/docs/tracks/java/tests)".

## macOS

Below are instructions for install using the most common method - using Homebrew.
If you'd rather, you can also [install on macOS without Homebrew](#installing-on-macos-without-homebrew).

## Installing

1. If you haven't installed [Homebrew](http://brew.sh), yet, do so now:

```sh
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
```

2. Tap the [Homebrew Cask](https://github.com/Homebrew/homebrew-cask-versions) — this allows us to install a specific JDK version.

```sh
brew tap homebrew/cask-versions
```

3. Install the JDK:

```sh
brew install --cask temurin21
```

4. Install Gradle:

```sh
brew install gradle
```

You now are ready to get started with the Java track of Exercism!

To get started, see "[Running the Tests](https://exercism.org/docs/tracks/java/tests)".

## Linux

Below are instructions for install using the package manager of your distro.
If you'd rather, you can also [install on Linux without a package manager](#installing-on-linux-without-a-package-manager).

- [Debian](#debian)
- [Other Linux distributions](#other-linux-distributions)

### Debian

If you are using Debian or its derivatives (like Ubuntu), use APT.

~~~~exercism/note
These steps have been verified on Ubuntu 20.04 and 22.04
~~~~

1. Install the JDK:

```sh
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get install openjdk-21-jdk
```

2. Install Gradle:

```sh
sudo add-apt-repository ppa:cwchien/gradle
sudo apt-get update
sudo apt-get install gradle
```

You now are ready to get started with the Java track of Exercism!

To get started, see "[Running the Tests](https://exercism.org/docs/tracks/java/tests)".

### Other Linux distributions

There are a lot of ways to install JDK 21, but one of the easiest ways is to use SDKMAN, which lets you install
both OpenJDK 21 and the latest Gradle with ease.

Use the following steps:

1. Install SDKMAN:

```sh
curl -s "https://get.sdkman.io" | bash
```

(if that doesn't work, take a look at the [installation instructions](https://sdkman.io/install))

2. Install OpenJDK 21:

```sh
sdk install java 21.0.1-tem
```

3. Install Gradle:

```sh
sdk install gradle
```

You now are ready to get started with the Java track of Exercism!

To get started, see "[Running the Tests](https://exercism.org/docs/tracks/java/tests)".

## Install Manually

- [Installing on Windows manually](#installing-on-windows-manually)
- [Installing on macOS without Homebrew](#installing-on-macos-without-homebrew)
- [Installing on Linux without a package manager](#installing-on-linux-without-a-package-manager)

### Installing on Windows manually

~~~~exercism/note
These instructions are intended for experienced Windows users.
If you don't already know how to set environment variables or feel comfortable managing the directory structure, we highly recommend you use the Chocolatey-based install, [above](#windows).
~~~~

1. Install the JDK:
- Download "**OpenJDK 21 (LTS)**" from [Adoptium](https://adoptium.net/temurin/releases/?os=windows&arch=x64&package=jdk&version=21) (choose **".msi"**).
- Run the installer, using all the defaults.
2. Install Gradle:
- Download "**Binary only distribution**" from the [Gradle download page](https://gradle.org/gradle-download/).
- Unzip the archive. We recommend a place like `C:\Users\JohnDoe\Tools`.
- Add a new system environment variable named `GRADLE_HOME` and set it to the path you just created (e.g. `C:\Users\JohnDoe\Tools\gradle-x.y`).
- Update the system `Path` to include the `bin` directory from Gradle's home (e.g. `Path`=`...;%GRADLE_HOME%\bin`).

You now are ready to get started with the Java track of Exercism!

To get started, see "[Running the Tests](https://exercism.org/docs/tracks/java/tests)".

### Installing on macOS without Homebrew

~~~~exercism/note
These instructions are intended for experienced macOS users.
Unless you specifically do not want to use a package manager, we highly recommend using the Homebrew-based installation instructions, [above](#macos).
~~~~

1. Install the JDK:
- Download "**OpenJDK 21 (LTS)**" from [Adoptium](https://adoptium.net/temurin/releases/?os=mac&package=jdk&version=21) (choose **".pkg"**).
- Run the installer, using all the defaults.
2. Install Gradle:

- Download "**Binary only distribution**" from the [Gradle download page](https://gradle.org/gradle-download/).
- Unpack Gradle:

```sh
mkdir ~/tools
cd ~/tools
unzip ~/Downloads/gradle-*-bin.zip
cd gradle*
```

- Configure Gradle and add it to the path:

```sh
cat << DONE >> ~/.bashrc
export GRADLE_HOME=`pwd`
export PATH=\$PATH:\$GRADLE_HOME/bin
DONE
```

You now are ready to get started with the Java track of Exercism!

To get started, see "[Running the Tests](https://exercism.org/docs/tracks/java/tests)".

### Installing on Linux without a package manager

```exercism/note
These instructions are intended for experienced Linux users.
Unless you specifically do not want to use a package manager, we highly recommend using the installation instructions, [above](#linux).
```

1. Install the JDK:
- Choose your distribution and download "**OpenJDK 21 (LTS)**" from [Adoptium](https://adoptium.net/temurin/releases/?os=linux&package=jdk&version=21) (choose **".tar.gz"**).
- Run the installer, using all the defaults.
2. Install Gradle:

- Download "**Binary only distribution**" from the [Gradle download page](https://gradle.org/gradle-download/).
- Unpack Gradle:
## Java IDEs

```sh
mkdir ~/tools
cd ~/tools
unzip ~/Downloads/gradle-*-bin.zip
cd gradle*
```
There are many free IDEs available for Java.
Here are some popular choices:

- Configure Gradle and add it to the path:
- [IntelliJ IDEA Community Edition][intellij-idea]
- [Eclipse][eclipse]
- [Visual Studio Code with the Java extension][vscode-java]

```sh
cat << DONE >> ~/.bashrc
export GRADLE_HOME=`pwd`
export PATH=\$PATH:\$GRADLE_HOME/bin
DONE
```
## Next steps

You now are ready to get started with the Java track of Exercism!

To get started, see "[Running the Tests](https://exercism.org/docs/tracks/java/tests)".

## Java IDEs

There are many Java IDEs available. The three most popular are:

- [IntelliJ IDEA](https://www.jetbrains.com/idea/download/) (download the "Community" edition)
- [Eclipse](https://www.eclipse.org/downloads/)
- [NetBeans](https://netbeans.org/downloads/) (download the "Java SE" bundle)
To get started, see "[Running the Tests][exercism-java-tests-docs]".

and there are [others](https://en.wikibooks.org/wiki/Java_Programming/Java_IDEs).
[eclipse]: https://www.eclipse.org/downloads/
[exercism-java-tests-docs]: https://exercism.org/docs/tracks/java/tests
[intellij-idea]: https://www.jetbrains.com/idea/download/
[adoptium]: https://adoptium.net
[adoptium-installation-guide]: https://adoptium.net/en-GB/installation/
[vscode-java]: https://code.visualstudio.com/docs/languages/java
14 changes: 8 additions & 6 deletions docs/TESTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ Choose your operating system:
4. Run the tests:

```batchfile
C:\Users\JohnDoe>gradle test
C:\Users\JohnDoe>gradlew.bat test
```

_(Don't worry about the tests failing, at first, this is how you begin each exercise.)_

5. Solve the exercise. Find and work through the `instructions.append.md` guide ([view on GitHub](https://github.com/exercism/java/blob/main/exercises/practice/hello-world/.docs/instructions.append.md#tutorial)).
5. Solve the exercise. Find and work through the `instructions.append.md` guide ([view on GitHub][hello-world-tutorial]).

Good luck! Have fun!

Expand All @@ -50,12 +50,12 @@ Good luck! Have fun!
3. Run the tests:

```sh
gradle test
./gradlew test
```

_(Don't worry about the tests failing, at first, this is how you begin each exercise.)_

4. Solve the exercise. Find and work through the `instructions.append.md` guide ([view on GitHub](https://github.com/exercism/java/blob/main/exercises/practice/hello-world/.docs/instructions.append.md#tutorial)).
4. Solve the exercise. Find and work through the `instructions.append.md` guide ([view on GitHub][hello-world-tutorial]).

Good luck! Have fun!

Expand All @@ -76,11 +76,13 @@ Good luck! Have fun!
3. Run the tests:

```sh
gradle test
./gradlew test
```

_(Don't worry about the tests failing, at first, this is how you begin each exercise.)_

4. Solve the exercise. Find and work through the `instructions.append.md` guide ([view on GitHub](https://github.com/exercism/java/blob/main/exercises/practice/hello-world/.docs/instructions.append.md#tutorial)).
4. Solve the exercise. Find and work through the `instructions.append.md` guide ([view on GitHub][hello-world-tutorial]).

Good luck! Have fun!

[hello-world-tutorial]: https://github.com/exercism/java/blob/main/exercises/practice/hello-world/.docs/instructions.append.md#tutorial
6 changes: 6 additions & 0 deletions exercises/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ subprojects {
if(project.name == 'concept' || project.name == 'practice')
return

// Add a task that creates Gradle wrappers for all exercises,
// matching the Gradle version of the project root.
tasks.register('allWrappers', Wrapper) {
gradleVersion = "$gradle.gradleVersion"
}

sourceSets {
// Set the directory containing the reference solution as the default source set. Default
// compile tasks will now run against this source set.
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading