Java CLI test harness demands gradle which doesn't work

% uname -a
Linux kripke 6.2.0-33-generic #33~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Sep  7 10:33:52 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
% javac -version 
javac 18.0.2-ea
% apt list | egrep '^(ant|maven|gradle)'
ant/jammy,jammy,now 1.10.12-1 all [installed]
maven/jammy,jammy,now 3.6.3-5 all [installed]
... other entries snipped ...

When you download a Java exercism, the test framework that arrives demands gradle. I installed gradle using apt, and no problems were reported. ‘gradle test’, however, fails miserably.

* What went wrong:
Could not create service of type ScriptPluginFactory using BuildScopeServices.createScriptPluginFactory().
Could not create service of type PluginResolutionStrategyInternal using BuildScopeServices.createPluginResolutionStrategy().

Hi. I’m not a “tech support” from here, but I have no issues with running the exercises with gradle.

I think there is need for more information: which exercise have you attempted?

Also try to run a gradle --info test and paste the full output of the command here.

Also, apt packages for gradle may be out of date: perhaps it would be wise to follow the installation instructions from gradle.org? Installing Gradle

“It works for me” is never a helpful response.
Which exercise didn’t make the slightest difference.
I have for obvious reasons deleted gradle and the exercism/java
directory.
So I’ve reinstalled gradle, which has an insane number of dependencies. And here’s what happens.
exercism% gradle --info test
Initialized native services in: /home/ok/.gradle/native
The client will now receive all logging from the daemon (pid: 1108876). The daemon log file: /home/ok/.gradle/daemon/4.4.1/daemon-1108876.out.log
Starting 2nd build in daemon [uptime: 1 mins 5.445 secs, performance: 97%]
Using 4 worker leases.
Creating new cache for fileHashes, path /home/ok/exercism/.gradle/4.4.1/fileHashes/fileHashes.bin, access org.gradle.cache.internal.DefaultCacheAccess@7a6c8fb2

FAILURE: Build failed with an exception.

  • What went wrong:
    Could not create service of type ScriptPluginFactory using BuildScopeServices.createScriptPluginFactory().

Could not create service of type PluginResolutionStrategyInternal using BuildScopeServices.createPluginResolutionStrategy().

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 0s
exercism% exit
exit
Script done.

You see that it’s nothing to do with the exercise.
Let’s try again with all the recommended options.
Ah. What happens is that this appalling interface won’t let me tell you what I see. The debug output is too big,

That’s the thing. Gradle has one dependency: java. I suspect using apt installs for gradle, because they are not supported by the gradle team. Take a look at the gradle install manual. APT is installing Gradle 4?? This is from 259 before Methuselah… :slight_smile:

And the exercise may have yes, all to do with it: each exercise is maintained separatedly, and the build.gradle used can be different, or the presence or not of a gradle wrapper.

Ideally all projects should have the wrapper so you don’t install gradle at all: You can use the ./gradlew script to run gradle, which is what I prefer to use.

For example, for the markdown project, I can see the gradle wrapper there:


To run the tests, I don’t need to install a thing:

cd /mnt/e/…whatever…/markdown
./gradlew test

To use ./gradlew instead of installing gradle have big advantages, because it documents the gradle version being used (inside gradle/wrapper/wrapper.properties), so you never face the issue of building a project with the wrong gradle version.

Some other tracks tell you exactly what you have to install.

OK, so I download Gradle 8.6 from Gradle | Installation
and I go through the process of manually installing it. Fine.
So I download annalyns-infiltration. And the HELP.md file says
to do ‘gradlew test’.
But there is no gradlew. None. There is no file in the gradle
distribution called gradlew* .
Fortunately, ‘gradle test’ does the job,
Now it all seems to work. Except that there is a warning:

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

So we’ve resolved it to the following three issues.
(1) Tell people before they start to ensure that they have an up-to-date installation of gradle, telling them what up-to-date means and how to get it.
(2) HELP.md should either say to use ‘gradle’ instead of ‘gradlew’ OR should explain what to do if the gradle installation from the gradle web site did not come with a ‘gradlew’ command. (Was it supposed to come with the exercise?)
(3) Do something about the upcoming gradle 9.0 incompatibilities.

CCing @sanderploegsma who is the Java maintainer.

1 Like

Tangentially, a couple of weeks ago there was a PR for the exercism CLI tool to use the gradle wrapper for the exercism test command.

Basically @abmpicoli is right: the correct way to run Gradle for the Exercism exercises in the Java track is by using the Gradle wrapper. This makes sure that the local versions of the tooling match the versions used when authoring exercises.

When downloading an exercise using the CLI it should download the Gradle wrapper files:

~/Dev/exercism/workspace/java on  main ⌚ 20:29:11
$ exercism download --exercise hamming --track java

Downloaded to
/Users/sander/Dev/exercism/workspace/java/hamming

~/Dev/exercism/workspace/java on  main! ⌚ 20:29:44
$ tree -a hamming
hamming
├── .exercism
│   ├── config.json
│   └── metadata.json
├── HELP.md
├── README.md
├── build.gradle
├── gradle
│   └── wrapper
│       ├── gradle-wrapper.jar
│       └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── src
    ├── main
    │   └── java
    │       └── Hamming.java
    └── test
        └── java
            └── HammingTest.java

9 directories, 11 files

Notice the gradlew, gradlew.bat and gradle/wrapper/* files.

To use the gradle wrapper, navigate to the exercise directory and run it. Note that you have to make it executable first as the Exercism CLI does not seem to retain the permissions set on the file in the track source code - this will hopefully be resolved in the future.

~/Dev/exercism/workspace/java on  main! ⌚ 20:29:55
$ cd hamming

~/Dev/exercism/workspace/java/hamming on  main! ⌚ 20:31:29
$ chmod +x gradlew

~/Dev/exercism/workspace/java/hamming on  main! ⌚ 20:32:46
$ ./gradlew test       

> Task :test FAILED

HammingTest > testCompleteDistanceInSingleLetterDifferentStrands() SKIPPED

HammingTest > testNoDistanceBetweenEmptyStrands() FAILED
    java.lang.UnsupportedOperationException: Delete this statement and write your own implementation.
        at Hamming.<init>(Hamming.java:3)
        at HammingTest.testNoDistanceBetweenEmptyStrands(HammingTest.java:11)

HammingTest > testNoDistanceBetweenShortIdenticalStrands() SKIPPED

HammingTest > testDisallowLeftEmptyStrand() SKIPPED

HammingTest > testDistanceInLongIdenticalStrands() SKIPPED

HammingTest > testDisallowRightEmptyStrand() SKIPPED

HammingTest > testDistanceInLongDifferentStrands() SKIPPED

HammingTest > testValidatesFirstStrandNotLonger() SKIPPED

HammingTest > testValidatesSecondStrandNotLonger() SKIPPED

9 tests completed, 1 failed, 8 skipped

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':test'.
> There were failing tests. See the report at: file:///Users/sander/Dev/exercism/workspace/java/hamming/build/reports/tests/test/index.html

* Try:
> Run with --scan to get full insights.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.5/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD FAILED in 1s
3 actionable tasks: 3 executed

(The tests obviously fail because I freshly downloaded the exercise without actually implementing something)

Note that we only just switched to using the Gradle wrapper on the Java track, so exercises that you downloaded before that change happened (about two weeks ago, incidentally around the time this topic was created) won’t contain the Gradle Wrapper files just yet - although they should then also contain an older HELP.md that still instructs to use your local Gradle installation instead of the wrapper.

If this is the case for you, downloading again with the --force flag should download the Gradle wrapper files for you:

~/Dev/exercism/workspace/java on  main! ⌚ 20:41:03
$ tree -a hello-world 
hello-world
├── .exercism
│   ├── config.json
│   └── metadata.json
├── HELP.md
├── README.md
├── build.gradle
└── src
    ├── main
    │   └── java
    │       ├── Greeter.class
    │       └── Greeter.java
    └── test
        └── java
            └── GreeterTest.java

7 directories, 8 files

~/Dev/exercism/workspace/java on  main! ⌚ 20:41:07
$ exercism download --exercise hello-world --track java --force

Downloaded to
/Users/sander/Dev/exercism/workspace/java/hello-world

~/Dev/exercism/workspace/java on  main! ⌚ 20:41:16
$ tree -a hello-world 
hello-world
├── .exercism
│   ├── config.json
│   └── metadata.json
├── HELP.md
├── README.md
├── build.gradle
├── gradle
│   └── wrapper
│       ├── gradle-wrapper.jar
│       └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── src
    ├── main
    │   └── java
    │       ├── Greeter.class
    │       └── Greeter.java
    └── test
        └── java
            └── GreeterTest.java

9 directories, 12 files

Note that this will overwrite all local files that were not yet submitted. If you have submitted a solution for the exercise already it will download that, otherwise it will revert to the initial solution you got when starting the exercise.

1 Like

@nzok Please don’t speak to people like this if you’re going to partake in Exercism’s community. @abmpicoli invested his time to help you - just because his information didn’t immediately solve the issue for you doesn’t mean you get to respond to him in such a disrespectful and dismissive tone. If you’re happy to abide by that, then great - welcome to the community. If not, then please just solve your problems by yourself or use a different community where this sort of communication is acceptable. Thank you :slight_smile:

Speak like what? What did I say that was untrue or unhelpful?

For what it’s worth, people on this track need to be advised that if they DO use a manual installation of the latest gradle, they should NOT use gradlew as the HELP.md suggests when the exercise actually does come with a gradlew. I found this out the hard way when ‘gradlew test’ tried to install 8.5 instead of the 8.6 I had installed.

Yep - this is all great to work out, and due to people digging into what you said it became clear and now we can make progress.

However, “meta” comments like these just come across as rude. Not thanking people for taking the time to try and help also comes across as rude.

People don’t have magic answer to questions. They have to ask questions and explore things to be able to work out the correct solution. Being grateful that someone is digging into a problem with you is a key part of communicating in the Exercism-way.

Responding with tone such as “… didn’t make the slightest difference” (em added) suggests that because their question didn’t help, it was a ridiculous suggestion. Instead, saying something like “Thanks for the suggestion - I’ve tried a few exercises but have the same issue with them all” is respectful of someone trying to help.

We have a dedicated article on this if you would like to understand more what I’m saying: The words that we use | Exercism's Docs

I understand that many communities and spaces don’t hold the same values as we do with regards to empathetic communication, and I make no judgement of that. But I do ask that people communicate here in a way that acknowledge gratefully the time and energy we give to support each other.

Thanks.

2 Likes

“didn’t make the slightest difference” is pure information with no tone.
“works for me” means “you are too dumb to do it right” – it’s an insult.

Sorry if you have considered my answer insulting. It was never my intention. There was not enough information to understand what the problem was. You seemed to be unfamiliar with gradle, so I asked you to provide more data for a diagnostic. What you did provide wasn’t enough to help you.

1 Like