diff --git a/Jenkinsfile b/Jenkinsfile index fa5ce1402174..cb0f6f5ddc13 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -58,7 +58,7 @@ pipeline { 'build-gpu-cuda8.0': { BuildCUDA(cuda_version: '8.0') }, 'build-gpu-cuda9.2': { BuildCUDA(cuda_version: '9.2') }, 'build-gpu-cuda10.0': { BuildCUDA(cuda_version: '10.0') }, - 'build-jvm-spark2.4.1': { BuildJVMSpark(spark_version: '2.4.1') }, + 'build-jvm-packages': { BuildJVMPackages(spark_version: '2.4.1') }, 'build-jvm-doc': { BuildJVMDoc() } ]) } @@ -76,7 +76,8 @@ pipeline { 'test-python-gpu-cuda10.0': { TestPythonGPU(cuda_version: '10.0') }, 'test-cpp-gpu': { TestCppGPU(cuda_version: '10.0') }, 'test-cpp-mgpu': { TestCppGPU(cuda_version: '10.0', multi_gpu: true) }, - 'test-jvm-test': { TestJVM() }, + 'test-jvm-jdk8': { CrossTestJVMwithJDK(jdk_version: '8') }, + 'test-jvm-jdk11': { CrossTestJVMwithJDK(jdk_version: '11') }, 'test-r-3.4.4': { TestR(r_version: '3.4.4') }, 'test-r-3.5.3': { TestR(r_version: '3.5.3') } ]) @@ -164,7 +165,7 @@ def BuildCUDA(args) { } } -def BuildJVMSpark(args) { +def BuildJVMPackages(args) { node('linux && cpu') { echo "Build XGBoost4J-Spark with Spark ${args.spark_version}" container_type = "jvm" @@ -172,6 +173,8 @@ def BuildJVMSpark(args) { sh """ ${dockerRun} ${container_type} ${docker_binary} tests/ci_build/build_jvm_packages.sh """ + echo 'Stashing XGBoost4J JAR...' + stash name: 'xgboost4j_jar', includes: 'jvm-packages/xgboost4j/target/*.jar' } } @@ -185,7 +188,7 @@ def BuildJVMDoc() { ${dockerRun} ${container_type} ${docker_binary} tests/ci_build/build_jvm_doc.sh ${BRANCH_NAME} """ archiveArtifacts artifacts: "jvm-packages/${BRANCH_NAME}.tar.bz2", allowEmptyArchive: true - echo 'Deploying doc...' + echo 'Uploading doc...' s3Upload file: "jvm-packages/${BRANCH_NAME}.tar.bz2", bucket: 'xgboost-docs', acl: 'PublicRead', path: "${BRANCH_NAME}.tar.bz2" } } @@ -211,9 +214,16 @@ def TestCppGPU(args) { } } -def TestJVM() { +def CrossTestJVMwithJDK(args) { node('linux && cpu') { - echo "Test JVM packages" + unstash name: 'xgboost4j_jar' + echo "Test XGBoost4J on a machine with JDK ${args.jdk_version}" + container_type = "jvm_cross" + docker_binary = "docker" + docker_args = "--build-arg JDK_VERSION=${args.jdk_version}" + sh """ + ${dockerRun} ${container_type} ${docker_binary} ${docker_args} tests/ci_build/test_jvm_cross.sh + """ } } diff --git a/jvm-packages/xgboost4j-tester/generate_pom.py b/jvm-packages/xgboost4j-tester/generate_pom.py new file mode 100644 index 000000000000..86b2af43a9ba --- /dev/null +++ b/jvm-packages/xgboost4j-tester/generate_pom.py @@ -0,0 +1,150 @@ +import sys + +pom_template = """ + + + + 4.0.0 + + ml.dmlc + xgboost4j-tester + 1.0-SNAPSHOT + + xgboost4j-tester + + + UTF-8 + {maven_compiler_source} + {maven_compiler_target} + {scala_version} + {scala_binary_version} + + + + + com.esotericsoftware.kryo + kryo + 2.21 + + + org.scala-lang + scala-compiler + ${{scala.version}} + + + org.scala-lang + scala-reflect + ${{scala.version}} + + + org.scala-lang + scala-library + ${{scala.version}} + + + commons-logging + commons-logging + 1.2 + + + com.typesafe.akka + akka-actor_${{scala.binary.version}} + 2.3.11 + compile + + + com.typesafe.akka + akka-testkit_${{scala.binary.version}} + 2.3.11 + test + + + org.scalatest + scalatest_${{scala.binary.version}} + 3.0.0 + test + + + junit + junit + 4.11 + test + + + ml.dmlc + xgboost4j + {xgboost4j_version} + + + ml.dmlc + xgboost4j + {xgboost4j_version} + tests + test-jar + test + + + + + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.1 + + + ml.dmlc:xgboost4j + + + + + + +""" + +if __name__ == '__main__': + if len(sys.argv) != 6: + print('Usage: {} [xgboost4j version] [maven compiler source level] [maven compiler target level] [scala version] [scala binary version]'.format(sys.argv[0])) + sys.exit(1) + with open('pom.xml', 'w') as f: + print(pom_template.format(xgboost4j_version=sys.argv[1], + maven_compiler_source=sys.argv[2], + maven_compiler_target=sys.argv[3], + scala_version=sys.argv[4], + scala_binary_version=sys.argv[5]), file=f) diff --git a/jvm-packages/xgboost4j-tester/src/main/java/ml/dmlc/App.java b/jvm-packages/xgboost4j-tester/src/main/java/ml/dmlc/App.java new file mode 100644 index 000000000000..4e4571838a20 --- /dev/null +++ b/jvm-packages/xgboost4j-tester/src/main/java/ml/dmlc/App.java @@ -0,0 +1,13 @@ +package ml.dmlc; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + } +} diff --git a/jvm-packages/xgboost4j-tester/src/test/java/ml/dmlc/AppTest.java b/jvm-packages/xgboost4j-tester/src/test/java/ml/dmlc/AppTest.java new file mode 100644 index 000000000000..22eeb397cf11 --- /dev/null +++ b/jvm-packages/xgboost4j-tester/src/test/java/ml/dmlc/AppTest.java @@ -0,0 +1,20 @@ +package ml.dmlc; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +/** + * Unit test for simple App. + */ +public class AppTest +{ + /** + * Rigorous Test :-) + */ + @Test + public void shouldAnswerWithTrue() + { + assertTrue( true ); + } +} diff --git a/tests/ci_build/Dockerfile.jvm_cross b/tests/ci_build/Dockerfile.jvm_cross new file mode 100644 index 000000000000..cfd9b0883ca6 --- /dev/null +++ b/tests/ci_build/Dockerfile.jvm_cross @@ -0,0 +1,25 @@ +ARG JDK_VERSION +FROM ubuntu:18.04 + +# Environment +ENV DEBIAN_FRONTEND noninteractive + +# Install all basic requirements +RUN \ + apt-get update && \ + apt-get install -y tar unzip wget openjdk-${JDK_VERSION}-jdk + +ENV GOSU_VERSION 1.10 + +# Install lightweight sudo (not bound to TTY) +RUN set -ex; \ + wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-amd64" && \ + chmod +x /usr/local/bin/gosu && \ + gosu nobody true + +# Default entry-point to use if running locally +# It will preserve attributes of created files +COPY entrypoint.sh /scripts/ + +WORKDIR /workspace +ENTRYPOINT ["/scripts/entrypoint.sh"] diff --git a/tests/ci_build/build_jvm_doc.sh b/tests/ci_build/build_jvm_doc.sh index e7ddc75fe6ce..b7501894e04f 100755 --- a/tests/ci_build/build_jvm_doc.sh +++ b/tests/ci_build/build_jvm_doc.sh @@ -8,7 +8,7 @@ fi set -e set -x -# Initialize Maven cache +# Initialize local Maven repository ./tests/ci_build/initialize_maven.sh rm -rf build/ diff --git a/tests/ci_build/build_jvm_packages.sh b/tests/ci_build/build_jvm_packages.sh index 9a9178a9f842..5fd1390d34d2 100755 --- a/tests/ci_build/build_jvm_packages.sh +++ b/tests/ci_build/build_jvm_packages.sh @@ -3,7 +3,7 @@ set -e set -x -# Initialize Maven cache +# Initialize local Maven repository ./tests/ci_build/initialize_maven.sh rm -rf build/ diff --git a/tests/ci_build/test_jvm_cross.sh b/tests/ci_build/test_jvm_cross.sh new file mode 100755 index 000000000000..d7213f15d27f --- /dev/null +++ b/tests/ci_build/test_jvm_cross.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +set -e +set -x + +# Initialize local Maven repository +./tests/ci_build/initialize_maven.sh + +# Get version number of XGBoost4J and other auxiliary information +cd jvm-packages +xgboost4j_version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) +maven_compiler_source=$(mvn help:evaluate -Dexpression=maven.compiler.source -q -DforceStdout) +maven_compiler_target=$(mvn help:evaluate -Dexpression=maven.compiler.target -q -DforceStdout) +scala_version=$(mvn help:evaluate -Dexpression=scala.version -q -DforceStdout) +scala_binary_version=$(mvn help:evaluate -Dexpression=scala.binary.version -q -DforceStdout) + +# Install XGBoost4J JAR into local Maven repository +mvn install:install-file -Dfile=./jvm-packages/xgboost4j/target/xgboost4j-${xgboost4j_version}.jar -DgroupId=ml.dmlc -DartifactId=xgboost4j -Dversion=${xgboost4j_version} -Dpackaging=jar +mvn install:install-file -Dfile=./jvm-packages/xgboost4j/target/xgboost4j-${xgboost4j_version}-tests.jar -DgroupId=ml.dmlc -DartifactId=xgboost4j -Dversion=${xgboost4j_version} -Dpackaging=test-jar -Dclassifier=tests + +cd xgboost4j-tester +# Generate pom.xml for XGBoost4J-tester, a dummy project to run XGBoost4J tests +python3 ./generate_pom.py ${xgboost4j_version} ${maven_compiler_source} ${maven_compiler_target} ${scala_version} ${scala_binary_version} +# Run tests +mvn test + +set +x +set +e