I got a script (just a simplified excerpt for brevity) to build and package my app, but it boils down to generating WiX installer with:
jpackage \
--type msi \
--dest "$(cygpath -w "${base[build:dist]}")" \
--name "${appDisplayName}" \
--app-version "${version}" \
--app-image "$(cygpath -w "${base[build:app]}")" \
--license-file "$(cygpath -w resources/app/legal/LICENSE)" \
--vendor "${vendor}" \
--verbose \
--temp 'W:\_tmp_' \
--win-shortcut;
It fails with enigmatic: Command [light.exe, (...)] in (...) exited with 94 code. Which I found is about unresolved reference and particularly a reference to a shortcut icon: ...\config\bundle.wxf(10) : error LGHT0094 : Unresolved reference to symbol 'Icon:icon1798580986' in section 'Fragment:'.
When I examined generated WiX XML, I found this:
<?xml version="1.0" ?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<Fragment>
...
<DirectoryRef Id="DesktopFolder">
<Component Win64="yes" Id="cshortcut9906e12cdacb303ebb5e48c888cf6949" Guid="{9906e12c-dacb-303e-bb5e-48c888cf6949}">
...
<Shortcut Id="shortcut9906e12cdacb303ebb5e48c888cf6949" Name="..." WorkingDirectory="INSTALLDIR" Advertise="no" IconIndex="0" Target="[#filed2065cdc42e13
55f8bdbbefc93d540f3]" Icon="icon1798580986"></Shortcut>
</Component>
</DirectoryRef>
...
</Wix>
And indeed there's this "icon1798580986" value, which does not tell me anything and even WiX is lost here (after reading this this https://stackoverflow.com/a/21019152/2024692 I checked and confirmed that I actually do have WixUIExtension.dll in WiX bin folder).
When I remove --win-shortcut option, then MSI installer is generated, but unfortunately w/o shortcut icon on the desktop (the app has it's proper icons, thou, as I generated application image with --icon switch and with --resource-dir pointing to a.o. app icons).
As you probably guessed, this is called from Cygwin, so sometimes it needs fiddling with paths, especially when one calls Windows executables (hence these cygpath things).
Well, I wasn't able to find any constructive approaches how to simply allow my Java application packed with jpackage (from both JDK-14/15 EA with no success) to have nice shortcut icon after it gets installed. Does anyone knows how to fix this? Thanks in advance.
its easier to do with a gradle plugin
You need to set the proper icon file path and have a valid .ico file. This is how I did it:
jlink {
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher {
name = 'PDF Decorator'
jvmArgs = ['-Djdk.gtk.version=2'] // required due to a bug in Java: https://github.com/javafxports/openjdk-jfx/issues/175
}
jpackage {
installerOptions = [
'--description', project.description,
'--copyright', 'Copyrigth 2015-2019 WALCZAK.IT'
]
installerType = project.findProperty('installerType') // we will pass this from the command line (example: -PinstallerType=msi)
if (installerType == 'msi') {
imageOptions += ['--icon', 'src/main/resources/pdfdecorator/gui/icon.ico']
installerOptions += [
'--win-per-user-install', '--win-dir-chooser',
'--win-menu', '--win-shortcut'
]
}
if (installerType == 'pkg') {
imageOptions += ['--icon', 'src/main/resources/pdfdecorator/gui/icon.icns']
}
if (installerType in ['deb', 'rpm']) {
imageOptions += ['--icon', 'src/main/resources/pdfdecorator/gui/icon_256x256.png']
installerOptions += [
'--linux-menu-group', 'Office',
'--linux-shortcut'
]
}
if (installerType == 'deb') {
installerOptions += [
'--linux-deb-maintainer', 'office#walczak.it'
]
}
if (installerType == 'rpm') {
installerOptions += [
'--linux-rpm-license-type', 'GPLv3'
]
}
}
}
Here's an article how to build an app image using OpenJDK 11 and using OpenJDK 14 with jpackage only for building the installer / package: https://walczak.it/blog/distributing-javafx-desktop-applications-without-requiring-jvm-using-jlink-and-jpackage
You just had the pleasure given by convention over configuration
When using jpackage --app-image and --win-shorcut parameters then jpackage expect to find the executable and the icon at the root of app-image directory to create the shortcut. The executable and the icon must have the same name as the one provided using the --name parameter.
In your case jpackage expects:
$(cygpath -w "${base[build:app]}")\${appDisplayName}.exe
$(cygpath -w "${base[build:app]}")\${appDisplayName}.ico
to exists to be able to create the shortcut.
If error 94 happens without --win-shortcut
This might actually be a problem relating to the --app-image parameter given to jpackage! An indicator for that is the warning that the app-image wasn't created by jpackage.
If your destination parameter when creating the app-image looks like --dest target/app-image, then you have to use --app-image target/app-image/myapp when creating the installer. Using --app-image target/app-image results in this error. A minor oversight that can create a lot of head-scratching because of the cryptic message.
This seems to happen for the reason #Mumrah81 gave:
[...] jpackage expect to find the executable and the icon at the root of app-image directory to create the shortcut.
Related
I tried to build a simple App with Kotlin that uses kotlin.random.Random class on a GraalVM native image.
But this fails at runtime. Stacktrace see below.
As a workaround you can use the java standard java.util.Random class.
Can someone tell me how to use the Kotlin type?
App.kt
import kotlin.random.Random
fun main(args: Array<String>) {
println(Random.nextInt())
}
Dockerfile
############################################################################
# Graal Native Image Early-Access Build
#
# Make sure you configured Docker to use at least 6gb ram!
# build from project root dir with: docker build -t example-kotlin-random-graalvm-native:1.0.0-SNAPSHOT .
# run with: docker run -d example-kotlin-random-graalvm-native:1.0.0-SNAPSHOT
############################################################################
#####
# The builder image to build the native app
#####
FROM findepi/graalvm:native as builder
LABEL stage=builder
WORKDIR /builder
COPY ./build/libs/app-all.jar ./app.jar
RUN native-image \
--no-fallback \
--static \
-jar app.jar
#####
# The actual image to run
#####
FROM alpine:3.9
RUN apk --no-cache add ca-certificates
# App
WORKDIR /app
COPY --from=builder /builder/app .
EXPOSE $PORT
ENTRYPOINT ["./app"]
Runtime Error
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.oracle.svm.core.hub.ClassInitializationInfo.initialize(ClassInitializationInfo.java:290)
at java.lang.Class.ensureInitialized(DynamicHub.java:475)
at kotlin.random.Random.<clinit>(Random.kt:242)
at com.oracle.svm.core.hub.ClassInitializationInfo.invokeClassInitializer(ClassInitializationInfo.java:350)
at com.oracle.svm.core.hub.ClassInitializationInfo.initialize(ClassInitializationInfo.java:270)
at com.example.AppKt.main(App.kt:8)
Caused by: java.lang.InstantiationException: Type `kotlin.internal.jdk8.JDK8PlatformImplementations` can not be instantiated reflectively as it does not have a no-parameter constructor or the no-parameter constructor has not been added explicitly to the native image.
at java.lang.Class.newInstance(DynamicHub.java:793)
at kotlin.internal.PlatformImplementationsKt.<clinit>(PlatformImplementations.kt:41)
... 6 more
Minimal Working example Project here
You have to modify the reflections rules
add the following to the native-image arguments:
-H:ReflectionConfigurationFiles=/path/to/reflectconfig
and put the rules for the affected class into the reflectionconfig file:
[{
"name" : "kotlin.internal.jdk8.JDK8PlatformImplementations",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredFields" : true,
"allPublicFields" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true
}]
alternatively you can also specify the init method with the same file, read this
I'm having issues with Bouncycastle, which only arise when running the :lint task.
Generally it seems to be a Java 9 byte-code version 53.0 / ASM version conflict.
These are the dependencies:
// https://mvnrepository.com/artifact/org.bouncycastle
implementation "org.bouncycastle:bcprov-jdk15on:1.64"
implementation "org.bouncycastle:bcpkix-jdk15on:1.64"
Which cause the :lint task to throw processing errors:
> Task :mobile:lint
Error processing bcpkix-jdk15on-1.64.jar:META-INF/versions/9/module-info.class: broken class file? (This feature requires ASM6)
Error processing bcprov-jdk15on-1.64.jar:META-INF/versions/9/module-info.class: broken class file? (This feature requires ASM6)
META-INF/versions/9/module-info.class: broken class file? (This feature requires ASM6)
The same goes for:
// https://mvnrepository.com/artifact/com.google.code.gson/gson
implementation "com.google.code.gson:gson:2.8.6"
Since upgrading from 1.4.1 to 1.4.2-native-mt, it's the same again:
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.2-native-mt"
kotlin-stdlib-1.4.0.jar:META-INF\versions\9\module-info.class: broken class file? (Module requires ASM6)
As already mentioned this was introduced in Java 9, that Android does not support. You could just use packagingOptions to remove those classes.
android {
packagingOptions {
exclude "**/module-info.class"
}
}
This should not affect actual executed code and should also remove classes for lint checks as lint is working on bytecode.
Update: Please see my current answer, which nails the problem.
This answer is only being kept as an example for Gradle scripting.
When using old versions (likely built with Java 8), there are no such processing errors:
// https://mvnrepository.com/artifact/org.bouncycastle
implementation "org.bouncycastle:bcprov-jdk15on:1.60"
implementation "org.bouncycastle:bcpkix-jdk15on:1.60"
// https://mvnrepository.com/artifact/com.google.code.gson/gson
implementation "com.google.code.gson:gson:2.8.5"
The issue obviously was introduced with version 1.61 / 2.8.6 (likely built with Java 9).
It's annoying when Google brings one back to the own answer, which is not really an answer. Instead of keeping back the version or editing the JAR, I've wrote a DeleteModuleInfoTask and a shell script, which automates the deletion of module-info.class from any given Java dependency.Since commandLine only accepts a single command, one almost has to call a script. And this should serve as a good example for a custom Exec task.
For Linux: module_info.sh considers versions/9/module-info.class and module-info.class:
#!/usr/bin/env bash
GRADLE_CACHE_DIR=$HOME/.gradle/caches/modules-2/files-2.1
ZIP_PATHS=(META-INF/versions/9/module-info.class module-info.class)
if [[ $# -ne 3 ]]; then
echo "Illegal number of parameters"
exit 1
else
if [ -d "$GRADLE_CACHE_DIR" ]; then
DIRNAME=${GRADLE_CACHE_DIR}/$1/$2/$3
if [ -d "$DIRNAME" ]; then
cd ${DIRNAME} || exit 1
find . -name ${2}-${3}.jar | (
read ITEM;
for ZIP_PATH in "${ZIP_PATHS[#]}"; do
INFO=$(zipinfo ${ITEM} ${ZIP_PATH} 2>&1)
if [ "${INFO}" != "caution: filename not matched: ${ZIP_PATH}" ]; then
zip ${ITEM} -d ${ZIP_PATH} # > /dev/null 2>&1
fi
done
)
exit 0
fi
fi
fi
For Windows: module_info.bat depends on 7-Zip:
#echo off
REM delete module.info from JAR file - may interfere with the local IDE.
for /R %USERPROFILE%\.gradle\caches\modules-2\files-2.1\%1\%2\%3\ %%G in (%2-%3.jar) do (
if exist %%G (
7z d %%G META-INF\versions\9\module-info.class > NUL:
7z d %%G versions\9\module-info.class > NUL:
7z d %%G module-info.class > NUL:
)
)
Update: After some testing I came to the conclusion that it may be better to manually edit the file when developing on Windows, because Android Studio and Java will lock the JAR, which will subsequently prevent the edit and leave the temp file behind.
File tasks.gradle provides the DeleteModuleInfoTask:
import javax.inject.Inject
abstract class DeleteModuleInfoTask extends Exec {
#Inject
DeleteModuleInfoTask(String dependency) {
def os = org.gradle.internal.os.OperatingSystem.current()
def stdout = new ByteArrayOutputStream()
def stderr = new ByteArrayOutputStream()
ignoreExitValue true
standardOutput stdout
errorOutput stderr
workingDir "${getProject().getGradle().getGradleUserHomeDir()}${File.separator}caches${File.separator}modules-2${File.separator}files-2.1${File.separator}${dependency.replace(":", File.separator).toString()}"
String script = "${getProject().getRootDir().getAbsolutePath()}${File.separator}scripts${File.separator}"
def prefix = ""; def suffix = "sh"
if (os.isWindows()) {prefix = "cmd /c "; suffix = "bat"}
String[] item = dependency.split(":")
commandLine "${prefix}${script}module_info.${suffix} ${item[0]} ${item[1]} ${item[2]}".split(" ")
// doFirst {println "${commandLine}"}
doLast {
if (execResult.getExitValue() == 0) {
if (stdout.toString() != "") {
println "> Task :${project.name}:${name} ${stdout.toString()}"
}
} else {
println "> Task :${project.name}:${name} ${stderr.toString()}"
}
}
}
}
Example Usage:
// Bouncycastle
tasks.register("lintFixModuleInfoBcPkix", DeleteModuleInfoTask, "org.bouncycastle:bcpkix-jdk15on:1.64")
lint.dependsOn lintFixModuleInfoBcPkix
tasks.register("lintFixModuleInfoBcProv", DeleteModuleInfoTask, "org.bouncycastle:bcprov-jdk15on:1.64")
lint.dependsOn lintFixModuleInfoBcProv
// GSON
tasks.register("lintFixModuleInfoGson", DeleteModuleInfoTask, "com.google.code.gson:gson:2.8.6")
lint.dependsOn lintFixModuleInfoGson
// Kotlin Standard Library
tasks.register("lintFixModuleInfoKotlinStdLib", DeleteModuleInfoTask, "org.jetbrains.kotlin:kotlin-stdlib:1.4.32")
lint.dependsOn lintFixModuleInfoKotlinStdLib
Make sure to register these tasks only for a single module.
According to resmon "Resource Monitor" > "Associated Handles", studio64 and java may hold a lock on the JAR file, therefore 7-Zip may only be able to edit the archive when Android Studio and Java had been closed; at least it nicely works for CI on Linux.
The file module-info.class is part of the Java module system which was introduced since Java 9. As per this issue on Android IssueTracker, the bug has been be fixed since Android Studio 3.4.
I have got the following error message:
Error processing C:\Users\mypc\.gradle\caches\modules-2\files-2.1\com.google.code.gson\gson\2.8.6\9180733b7df8542621dc12e21e87557e8c99b8cb\gson-2.8.6.jar:module-info.class: broken class file? (This feature requires ASM6)
This error occurs without using a development system like Android Studio. I use Gradle 6.1.1.
I prevented the mistake as follows:
Open the file gson-2.8.6.jar which is named in the error message
Removing of the file module-info.class, which is located in the root
There is a more simple workaround. Basically the problem can be identified as "running Gradle with Java 8, while handling files which were built with Java 9". My new approach is building with Java 11 (GitHub Actions also builds with Java 11 and Gradle 6.7.1 would currently support up to Java 15).
After installing Java 11 with sudo dnf install java-11-openjdk
alternatives --display java will list the JDK to use.
For example: /usr/lib/jvm/java-11-openjdk-11.0.11.0.9-0.el8_3.x86_64:
On a side note, building with JDK 11 also fixes this warning:
Current JDK version 1.8.0_172-b11 has a bug (https://bugs.openjdk.java.net/browse/JDK-8007720) that prevents Room from being incremental. Consider using JDK 11+ or the embedded JDK shipped with Android Studio 3.5+.
The "embedded JDK shipped with Android Studio 3.5+" is still Java 8 ...
Im trying to upload my project to circleci but from some reason it fails in a dropdown called "$ play test", I have no idea what is it, and I dont have tests in my project at all.
this is the section im talking about:
and im getting error there, this is the error:
I deleted "- sbt test" from my circle.yml so its not that, and I saw another folder of test in play so I thought maybe its that, but its empty, so I created a file in it and put nothing in it and still getting the same error...its driving me crazy ://///
please helpppppp
if you need this is my circle.yml:
machine:
services:
- docker
java:
version: oraclejdk8
environment:
SBT_VERSION: 0.13.9
SBT_OPTS: "-Xms512M -Xmx1536M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256M"
dependencies:
cache_directories:
- "~/.sbt"
- "~/.ivy2"
- "~/.m2"
- "~/docker"
pre:
- wget --output-document=$HOME/bin/sbt-launch.jar https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/sbt-launch/"$SBT_VERSION"/sbt-launch.jar
- echo "java $SBT_OPTS -jar \`dirname \$0\`/sbt-launch.jar \"\$#\"" > $HOME/bin/sbt
- chmod u+x $HOME/bin/sbt
- sbt sbt-version
override:
- sbt clean update
post:
- find . -type f -regex ".*/target/test-reports/.*xml" -exec cp {} $CIRCLE_TEST_REPORTS/ \;
general:
artifacts:
- "target/universal/*.tgz"
deployment:
feature:
branch: /.*/
commands:
- docker login -e admin#something.com -u ${ART_USER} -p ${ART_KEY} docker-local.artifactoryonline.com
- sbt -DBUILD_NUMBER="${CIRCLE_BUILD_NUM}" docker:publish
CircleCI has a feature called Inference that looks at what language your project is in as well as directories found, file extensions, etc to guess what dependencies and test you have.
If you look to the right of where you saw "play test" you'll see that it says "inference" which means this test was a result of Interference and not circle.yml. Inference made an assumption you needed the Play test framework (https://www.playframework.com/) and thus ran a default check, play test (the $ is part of the prompt).
If this is not what you want, which looks to be the case, you'll need to override the test command to instead run whatever test you want. This would be something like:
test:
override:
- echo "This is my test"
- ./my-custom-command
More information: https://circleci.com/docs/configuration/#test
I am trying to simulate Hadoop YARN SLS (Scheduling Load Simulator) with the sources given in Hadoop's GitHub and the SLS source files are located in [REF-1].
Here the step I have done :
Using VMWARE as the Host.
Using Ubuntu 14.04
Installing Hadoop v 2.6.0 [REF-2]
User : hduser | group : hadoop
Installing any needed packages (e.g. maven)
Get the clonning file of Hadoop's GitHub [REF-1]
Syntax : git clone https://git.apache.org/hadoop.git
Result : hduser#ubuntu:~/hadoop$
I made the changes inside directory hduser#ubuntu:~/hadoop/hadoop-tools$
FYI : I used the codes from MaxinetSLS [REF-3] as the way I compile the source files. The SLS source files can be downloaded by using this syntax in Linux : git clone https://github.com/wette/netSLS.git. By default, I can run this program with no error. The SLS Simulator can work perfectly.
From MaxiNetSLS's source files, I copied this files below into my work in hduser#ubuntu:~/hadoop/hadoop-tools$ :
netSLS/generator > hduser#ubuntu:~/hadoop/hadoop-tools$
netSLS/html > hduser#ubuntu:~/hadoop/hadoop-tools$
netSLS/sls.sh > hduser#ubuntu:~/hadoop/hadoop-tools$
netSLS/sls/hadoop/ > hduser#ubuntu:~/hadoop/hadoop-tools/hadoop-sls$
Then, I modified some files as follows.
netSLS/sls.sh
#!/usr/bin/env bash
function print_usage {
echo -e "usage: sls.sh TraceFile"
echo -e
echo -e "Starts SLS with the given trace file."
}
if [[ -z $1 ]]; then
print_usage
exit 1
fi
TRACE_FILE=$(realpath $1)
if [[ ! -f ${TRACE_FILE} ]]; then
echo "File not found: ${TRACE_FILE}"
print_usage
exit 1
fi
cd hadoop-sls
OUTPUT_DIRECTORY="/tmp/sls"
mkdir -p ${OUTPUT_DIRECTORY}
ARGS="-inputsls ${TRACE_FILE}"
ARGS+=" -output ${OUTPUT_DIRECTORY}"
ARGS+=" -printsimulation"
mvn exec:java -Dexec.args="${ARGS}"
hduser#ubuntu:~/hadoop/hadoop-tools/hadoop-sls/pom.xml$
[REF-4]
hduser#ubuntu:~/hadoop/hadoop-tools$ nano hadoop-sls/hadoop/etc/hadoop/sls-runner.xml
[REF-5]
Next step, I try to :
Compile the script using hduser#ubuntu:~/hadoop/hadoop-tools/hadoop-sls$ mvn compile
Compiled with no error (mvn_compile_perfect.jpg).
Run the program using hduser#ubuntu:~/hadoop/hadoop-tools$ ./sls.sh generator/small.json
Got the error here (error_json_compile.jpg). :(
Until now, I have went through some information related with similar problems I faced [REF-6] and tried it, but I still get the same problem. I guess I think the problem is in the ~/hadoop/hadoop-tools/hadoop-sls/pom.xml I mistakenly modified. I have lack of knowledge with Linux Environment. :(
References : http://1drv.ms/21zcJIH (txt file)
*Cannot post more than 2 links in my post. :(
I'm trying to run a npm command inside of gradle task but I'm getting a strange error:
Caused by: net.rubygrapefruit.platform.NativeException: Could not start 'npm'
at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:27)
at net.rubygrapefruit.platform.internal.WrapperProcessLauncher.start(WrapperProcessLauncher.java:36)
at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:65)
... 2 more
Caused by: java.io.IOException: Cannot run program "npm" (in directory "/Users/psilva/Documents/projects/registrolivre"): error=2, No such file or directory
at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:25)
... 4 more
Caused by: java.io.IOException: error=2, No such file or directory
And this is my task:
task npmInstall(type: Exec) {
commandLine "npm", "install"
}
Could someone help?
If you are on Windows try this:
task npmInstall(type: Exec) {
commandLine "npm.cmd", "install"
}
instead of this:
task npmInstall(type: Exec) {
commandLine "npm", "install"
}
This answer worked for me with a different npm-related task. The recommendation there is to use an executable and args rather than commandLine.
executable 'npm'
args ['install']
Depending on your directory structure, you may also need to add the workingDir property and set it to the directory where your package.json lives.
As an alternative, the Gradle Node Plugin is also really handy for managing the most common Node tasks in a Gradle build. I use this plugin as the basis for my Node tasks and then create other custom tasks as needed.
If you are using Windows OS, you have to use 'npm.cmd' instead of 'npm'. Better to detect whether OS is windows or not and build your npm command. Please see the code snippet below,
import org.apache.tools.ant.taskdefs.condition.Os
task npmInstall(type: Exec) {
String npm = 'npm';
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
npm = 'npm.cmd'
}
workingDir 'src/main/webapp'
commandLine npm, 'install'
}
On MX Linux I installed node in linux with nvm and none of the other answers worked for me.
The problem is
NVM patches environment variables on terminal startup only. If the IDE is launched from Terminal, it inherits Terminal environment...
Indeed it works starting IJ from bash terminal with ./idea.sh
In my case, nvm added the pathced env variables at the end of my ~./bashrc. The following steps worked for me;
Move the lines below from ~/.bashrc to ~./profile
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
$ sudo ln -s "$(which node)" /usr/local/bin/node
In IJ configure npm
Logout and login (session restart for step 1)
UPDATE:
In order to run nvm from bash. The following lines must be added to .bashrc
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
I used #ALDRIN P VINCENT answer to solve this issue. But if you need to pass command line arguments to npm script, you can do this:
Let's say following system properties are passed to gradle script
gradle test-Dsome1=dev -Dsome2=https://www.google.com
In your test script in build.gradle, you will do this:
task apifunctionaltest(type: Exec) {
String npm = 'npm';
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
npm = 'npm.cmd'
}
commandLine npm, 'run', 'test', '--', '--some1='+System.getProperty("some1"), '--some2='+System.getProperty("some2")
}
The main command starts with commandLine npm… This line equates to:
npm run test -- --some1=dev --some2=https://www.google.com
The test script in package.json also should have ‘npm install’ (it depends) command so node modules are installed before tests run. And if modules are already installed, node will not waste time and reinstall them. test script should be something like this:
"scripts": {
"test": "npm install && webpack"
}
And then you can pick those command line args thru process.argv[2] and process.argv[3].
If you have a simple script like mine, then some1 and some2 will be in the 2nd and 3rd position of an array, respectively.