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

gradle: add package tests #277530

Merged
merged 1 commit into from
Mar 24, 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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 42 additions & 10 deletions pkgs/development/tools/build-managers/gradle/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,26 @@ rec {
]
}:

{ lib, stdenv, fetchurl, makeWrapper, unzip, ncurses5, ncurses6,

# The JDK/JRE used for running Gradle.
java ? defaultJava,

# Additional JDK/JREs to be registered as toolchains.
# See https://docs.gradle.org/current/userguide/toolchains.html
javaToolchains ? [ ]
{ lib
, stdenv
, fetchurl
, makeWrapper
, unzip
, ncurses5
, ncurses6
, testers
, runCommand
, writeText

# The JDK/JRE used for running Gradle.
, java ? defaultJava

# Additional JDK/JREs to be registered as toolchains.
# See https://docs.gradle.org/current/userguide/toolchains.html
, javaToolchains ? [ ]
}:

stdenv.mkDerivation rec {
stdenv.mkDerivation (finalAttrs: {
pname = "gradle";
inherit version;

Expand Down Expand Up @@ -99,6 +108,29 @@ rec {
echo ${ncurses6} >> $out/nix-support/manual-runtime-dependencies
'';

passthru.tests = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fails on darwin

FAILURE: Build failed with an exception.
* What went wrong:
Gradle could not start your build.
> Could not initialize native services.
   > Failed to load native library 'libnative-platform.dylib' for Mac OS X x86_64.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
gradle --version returned a non-zero exit code.
FAILURE: Build failed with an exception.
* What went wrong:
Gradle could not start your build.
> Could not initialize native services.
   > Failed to load native library 'libnative-platform.dylib' for Mac OS X x86_64.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
error: builder for '/nix/store/pdfs37wfivmii12mqmx95xp6vlzn53qz-actual.drv' failed with exit code 1;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems to suggest that Gradle doesn’t work on macOS at all. Guess I’ll have to try to find a macOS to test with.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out Gradle wants to extract the library to $HOME/native, which is not writable on macOS, apparently. Will try to figure out how to work around that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should work on macOS now.

version = testers.testVersion {
package = finalAttrs.finalPackage;
command = ''
env GRADLE_USER_HOME=$TMPDIR/gradle org.gradle.native.dir=$TMPDIR/native \
gradle --version
'';
};

java-application = testers.testEqualContents {
assertion = "can build and run a trivial Java application";
expected = writeText "expected" "hello\n";
actual = runCommand "actual" {
nativeBuildInputs = [ finalAttrs.finalPackage ];
src = ./tests/java-application;
} ''
cp -a $src/* .
env GRADLE_USER_HOME=$TMPDIR/gradle org.gradle.native.dir=$TMPDIR/native \
gradle run --no-daemon --quiet --console plain > $out
'';
};
};

meta = with lib; {
inherit platforms;
description = "Enterprise-grade build system";
Expand All @@ -121,7 +153,7 @@ rec {
maintainers = with maintainers; [ lorenzleutgeb liff ];
mainProgram = "gradle";
};
};
});

# NOTE: Default JDKs that are hardcoded below must be LTS versions
# and respect the compatibility matrix at
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
id('application')
}

application {
mainClass = 'Main'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class Main {
public static void main(String[] args) {
System.out.println("hello");
}
}
Loading