I am migrating my project to Gradle and I had a separate working Robolectric setup along with my App.
The Robolectric tests are under the test/ folder and they should include the app jar file (thanks to another SO question) and other dependecies at runtime.
The tests are launched by Gradle, but the classpath looks empty.
The gradle.build:
apply plugin: 'java'
test {
// The classpath.each prints:
// /test-robolectric/build/classes/test
// /test-robolectric/build/resources/test
// /test-robolectric/build/classes/main
// /test-robolectric/build/resources/main
classpath.each { file ->
println file.absolutePath
}
reports {
html.enabled = true
}
// show standard out and standard error of the test JVM(s) on the console
testLogging.showStandardStreams = false
// listen to events in the test execution lifecycle
beforeTest { descriptor ->
logger.lifecycle("Running test: " + descriptor)
}
}
dependencies {
compile project(':test-common:test-common-jar')
compile project(path: ':app', configuration: 'testJar')
compile 'org.robolectric:robolectric:2.3-SNAPSHOT'
compile 'com.google.android:android:4.+'
compile 'com.android.support:appcompat-v7:19+#jar'
compile 'com.android.support:support-v4:19.+'
compile 'com.google.inject:guice:4.0-beta:no_aop'
compile 'com.google.code.gson:gson:2.2.4'
compile 'org.functionaljava:functionaljava:3.1'
compile 'javax.inject:javax.inject:1#jar'
compile 'com.squareup:otto:1.3.4#jar'
compile 'net.jcip:jcip-annotations:1.0'
compile 'de.akquinet.android.androlog:androlog:1.0.5'
compile 'com.j256.ormlite:ormlite-android:4.48'
compile 'com.j256.ormlite:ormlite-core:4.48'
compile 'junit:junit:4.11'
compile 'org.mockito:mockito-all:1.9.+'
compile 'org.hamcrest:hamcrest-core:1.+'
compile 'com.squareup:fest-android:1.0.+'
}
repositories {
mavenLocal()
mavenCentral()
maven {
url 'http://repository.grepcode.com/java/ext'
}
}
I have also tried to put the dependecies declaration inside the test{} section to no avail. What am I missing here?
The specific exception:
java.lang.NoClassDefFoundError: android/content/Context
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:270)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:58)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:49)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:69)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
[...]
Related
I try to package my app using JPackage task of Jlink-badass plugin (I'm using Gradle as a builder tool), but I keep getting the following error during the JPackageImage phase (even with a simple hello world javafx application):
> Task :jpackageImage
java.lang.IllegalArgumentException: "Version [1.0-SNAPSHOT] contains invalid component [0-SNAPSHOT]"
> Task :jpackageImage FAILED
Execution failed for task ':jpackageImage'.
> Process 'command 'C:\Users\youss\Desktop\openjdk-17_windows-x64_bin\jdk-17/bin/jpackage.exe'' finished with non-zero exit value 1
* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':jpackageImage'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:145)
at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:282)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:143)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:131)
at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:77)
at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:51)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:56)
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:77)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:55)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:204)
at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:199)
at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:73)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:52)
at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:74)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:402)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:389)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:382)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:368)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.lambda$run$0(DefaultPlanExecutor.java:127)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:191)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.executeNextNode(DefaultPlanExecutor.java:182)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:124)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:61)
Caused by: org.gradle.process.internal.ExecException: Process 'command 'C:\Users\youss\Desktop\openjdk-17_windows-x64_bin\jdk-17/bin/jpackage.exe'' finished with non-zero exit value 1
at org.gradle.process.internal.DefaultExecHandle$ExecResultImpl.assertNormalExitValue(DefaultExecHandle.java:414)
at org.gradle.process.ExecResult$assertNormalExitValue.call(Unknown Source)
at org.beryx.jlink.impl.JPackageImageTaskImpl.execute(JPackageImageTaskImpl.groovy:57)
at org.beryx.jlink.JPackageImageTask.jpackageTaskAction(JPackageImageTask.groovy:87)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:104)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.doExecute(StandardTaskAction.java:58)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:51)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:29)
at org.gradle.api.internal.tasks.execution.TaskExecution$2.run(TaskExecution.java:239)
at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:29)
at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:26)
at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
at org.gradle.internal.operations.DefaultBuildOperationRunner.run(DefaultBuildOperationRunner.java:47)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:68)
at org.gradle.api.internal.tasks.execution.TaskExecution.executeAction(TaskExecution.java:224)
at org.gradle.api.internal.tasks.execution.TaskExecution.executeActions(TaskExecution.java:207)
at org.gradle.api.internal.tasks.execution.TaskExecution.executeWithPreviousOutputFiles(TaskExecution.java:190)
at org.gradle.api.internal.tasks.execution.TaskExecution.execute(TaskExecution.java:168)
at org.gradle.internal.execution.steps.ExecuteStep.executeInternal(ExecuteStep.java:89)
at org.gradle.internal.execution.steps.ExecuteStep.access$000(ExecuteStep.java:40)
at org.gradle.internal.execution.steps.ExecuteStep$1.call(ExecuteStep.java:53)
at org.gradle.internal.execution.steps.ExecuteStep$1.call(ExecuteStep.java:50)
at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:204)
at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:199)
at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:73)
at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:50)
at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:40)
at org.gradle.internal.execution.steps.RemovePreviousOutputsStep.execute(RemovePreviousOutputsStep.java:68)
at org.gradle.internal.execution.steps.RemovePreviousOutputsStep.execute(RemovePreviousOutputsStep.java:38)
at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:48)
at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:36)
at org.gradle.internal.execution.steps.CancelExecutionStep.execute(CancelExecutionStep.java:41)
at org.gradle.internal.execution.steps.TimeoutStep.executeWithoutTimeout(TimeoutStep.java:74)
at org.gradle.internal.execution.steps.TimeoutStep.execute(TimeoutStep.java:55)
at org.gradle.internal.execution.steps.CreateOutputsStep.execute(CreateOutputsStep.java:51)
at org.gradle.internal.execution.steps.CreateOutputsStep.execute(CreateOutputsStep.java:29)
at org.gradle.internal.execution.steps.CaptureStateAfterExecutionStep.execute(CaptureStateAfterExecutionStep.java:61)
at org.gradle.internal.execution.steps.CaptureStateAfterExecutionStep.execute(CaptureStateAfterExecutionStep.java:42)
at org.gradle.internal.execution.steps.BroadcastChangingOutputsStep.execute(BroadcastChangingOutputsStep.java:60)
at org.gradle.internal.execution.steps.BroadcastChangingOutputsStep.execute(BroadcastChangingOutputsStep.java:27)
at org.gradle.internal.execution.steps.BuildCacheStep.executeWithoutCache(BuildCacheStep.java:188)
at org.gradle.internal.execution.steps.BuildCacheStep.lambda$execute$1(BuildCacheStep.java:75)
at org.gradle.internal.Either$Right.fold(Either.java:175)
at org.gradle.internal.execution.caching.CachingState.fold(CachingState.java:59)
at org.gradle.internal.execution.steps.BuildCacheStep.execute(BuildCacheStep.java:73)
at org.gradle.internal.execution.steps.BuildCacheStep.execute(BuildCacheStep.java:48)
at org.gradle.internal.execution.steps.StoreExecutionStateStep.execute(StoreExecutionStateStep.java:38)
at org.gradle.internal.execution.steps.StoreExecutionStateStep.execute(StoreExecutionStateStep.java:27)
at org.gradle.internal.execution.steps.RecordOutputsStep.execute(RecordOutputsStep.java:36)
at org.gradle.internal.execution.steps.RecordOutputsStep.execute(RecordOutputsStep.java:22)
at org.gradle.internal.execution.steps.SkipUpToDateStep.executeBecause(SkipUpToDateStep.java:109)
at org.gradle.internal.execution.steps.SkipUpToDateStep.lambda$execute$2(SkipUpToDateStep.java:56)
at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:56)
at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:38)
at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:73)
at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:44)
at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:37)
at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:27)
at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:89)
at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:50)
at org.gradle.internal.execution.steps.ValidateStep.execute(ValidateStep.java:114)
at org.gradle.internal.execution.steps.ValidateStep.execute(ValidateStep.java:57)
at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.execute(CaptureStateBeforeExecutionStep.java:76)
at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.execute(CaptureStateBeforeExecutionStep.java:50)
at org.gradle.internal.execution.steps.SkipEmptyWorkStep.lambda$execute$2(SkipEmptyWorkStep.java:93)
at org.gradle.internal.execution.steps.SkipEmptyWorkStep.execute(SkipEmptyWorkStep.java:93)
at org.gradle.internal.execution.steps.SkipEmptyWorkStep.execute(SkipEmptyWorkStep.java:34)
at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsStartedStep.execute(MarkSnapshottingInputsStartedStep.java:38)
at org.gradle.internal.execution.steps.LoadPreviousExecutionStateStep.execute(LoadPreviousExecutionStateStep.java:43)
at org.gradle.internal.execution.steps.LoadPreviousExecutionStateStep.execute(LoadPreviousExecutionStateStep.java:31)
at org.gradle.internal.execution.steps.AssignWorkspaceStep.lambda$execute$0(AssignWorkspaceStep.java:40)
at org.gradle.api.internal.tasks.execution.TaskExecution$3.withWorkspace(TaskExecution.java:284)
at org.gradle.internal.execution.steps.AssignWorkspaceStep.execute(AssignWorkspaceStep.java:40)
at org.gradle.internal.execution.steps.AssignWorkspaceStep.execute(AssignWorkspaceStep.java:30)
at org.gradle.internal.execution.steps.IdentityCacheStep.execute(IdentityCacheStep.java:37)
at org.gradle.internal.execution.steps.IdentityCacheStep.execute(IdentityCacheStep.java:27)
at org.gradle.internal.execution.steps.IdentifyStep.execute(IdentifyStep.java:44)
at org.gradle.internal.execution.steps.IdentifyStep.execute(IdentifyStep.java:33)
at org.gradle.internal.execution.impl.DefaultExecutionEngine$1.execute(DefaultExecutionEngine.java:76)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:142)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:131)
at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:77)
at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:51)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:56)
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:77)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:55)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:204)
at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:199)
at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:73)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:52)
at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:74)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:402)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:389)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:382)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:368)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.lambda$run$0(DefaultPlanExecutor.java:127)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:191)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.executeNextNode(DefaultPlanExecutor.java:182)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:124)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:61)
My Gradle.Build
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.10'
id 'org.beryx.jlink' version '2.24.4'
}
group 'com.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
ext {
junitVersion = '5.7.1'
}
sourceCompatibility = '17'
targetCompatibility = '17'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
application {
mainModule = 'com.example.demo4'
mainClass = 'com.example.demo4.Runner'
}
javafx {
version = '17.0.1'
modules = ['javafx.controls', 'javafx.fxml']
}
dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
}
test {
useJUnitPlatform()
}
jlink {
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher {
name = 'Karrty'
}
}
More details
-I'm using JDK 17.
What I have tried
-I tried using different JDKs like 16 but still the same error.
not sure if this is a bug or something is it something that I doing is wrong
for whoever suffers from the same issue, just delete
version '1.0-SNAPSHOT'
in your Gradle.build, and then the tool will work as it is supposed to.
Issue
I tried to add the react-native-firebase library https://github.com/invertase/react-native-firebase and everything works perfectly on iOS. When it comes to integration on android, nothing works.
The project Builds correctly, but the app crashes (only in Android) right after the build with this output:
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 1099 file(s) to forward-jetify. Using 16 workers...
info Starting JS server...
info Launching emulator...
info Successfully launched emulator.
info Installing the app...
> Configure project :#react-native-firebase_analytics
:#react-native-firebase_analytics:firebase.bom using default value: 21.1.0
:#react-native-firebase_analytics package.json found at /Users/enzomanuelmangano/Desktop/Lavoro/halfy_app/node_modules/#react-native-firebase/analytics/package.json
:#react-native-firebase_analytics:version set from package.json: 6.0.3 (6,0,3 - 6000003)
:#react-native-firebase_analytics:android.compileSdk using custom value: 28:#react-native-firebase_analytics:android.targetSdk using custom value: 28
:#react-native-firebase_analytics:android.minSdk using custom value: 16
:#react-native-firebase_analytics:reactNativeAndroidDir /Users/enzomanuelmangano/Desktop/Lavoro/halfy_app/node_modules/react-native/android
> Configure project :#react-native-firebase_app
:#react-native-firebase_app:firebase.bom using default value: 21.1.0
:#react-native-firebase_app package.json found at /Users/enzomanuelmangano/Desktop/Lavoro/halfy_app/node_modules/#react-native-firebase/app/package.json
:#react-native-firebase_app:version set from package.json: 6.0.3 (6,0,3 - 6000003)
:#react-native-firebase_app:android.compileSdk using custom value: 28
:#react-native-firebase_app:android.targetSdk using custom value: 28
:#react-native-firebase_app:android.minSdk using custom value: 16
:#react-native-firebase_app:reactNativeAndroidDir /Users/enzomanuelmangano/Desktop/Lavoro/halfy_app/node_modules/react-native/android
> Configure project :app
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
> Task :app:processDebugGoogleServices
Parsing json file: /Users/enzomanuelmangano/Desktop/Lavoro/halfy_app/android/app/google-services.j
son
> Task :app:installDebug
12:49:58 V/ddms: execute: running am get-config
12:49:58 V/ddms: execute 'am get-config' on 'emulator-5554' : EOF hit. Read: -1
12:49:58 V/ddms: execute: returning
Installing APK 'app-debug.apk' on '3.7_WVGA_Nexus_One_API_28(AVD) - 9' for app:debug
12:49:58 D/app-debug.apk: Uploading app-debug.apk onto device 'emulator-5554'
12:49:58 D/Device: Uploading file onto device 'emulator-5554'
12:49:58 D/ddms: Reading file permision of /Users/enzomanuelmangano/Desktop/Lavoro/halfy_app/android/app/build/outputs/apk/debug/app-debug.apk as: rw-r--r--
12:49:59 V/ddms: execute: running pm install -r -t "/data/local/tmp/app-debug.apk"
12:50:02 V/ddms: execute 'pm install -r -t "/data/local/tmp/app-debug.apk"' on 'emulator-5554' : E
OF hit. Read: -1
12:50:02 V/ddms: execute: returning
12:50:02 V/ddms: execute: running rm "/data/local/tmp/app-debug.apk"
12:50:02 V/ddms: execute 'rm "/data/local/tmp/app-debug.apk"' on 'emulator-5554' : EOF hit. Read:
-1
12:50:02 V/ddms: execute: returning
Installed on 1 device.
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.1.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 7s
192 actionable tasks: 3 executed, 189 up-to-date
info Connecting to the development server...
info Starting the app on "emulator-5554"...
Starting: Intent { cmp=com.halfy_app/.MainActivity }
MBP-di-Enzo:halfy_app enzomanuelmangano$
MBP-di-Enzo:halfy_app enzomanuelmangano$ react-native run-android --log
error: unknown option `--log'
MBP-di-Enzo:halfy_app enzomanuelmangano$ react-native run-android -log
error: unknown option `-l'
MBP-di-Enzo:halfy_app enzomanuelmangano$ react-native run-android
error React Native CLI uses autolinking for native dependencies, but the following modules are linked manually:
- react-native-maps (to unlink run: "react-native unlink react-native-maps")
This is likely happening when upgrading React Native from below 0.60 to 0.60 or above. Going forward, you can unlink this dependency via "react-native unlink <dependency>" and it will be included in your app automatically. If a library isn't compatible with autolinking, disregard this message and notify the library maintainers.
Read more about autolinking: https://github.com/react-native-community/cli/blob/master/docs/autolinking.md
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 1099 file(s) to forward-jetify. Using 16 workers...
info JS server already running.
info Installing the app...
> Configure project :#react-native-firebase_analytics
:#react-native-firebase_analytics:firebase.bom using default value: 21.1.0
:#react-native-firebase_analytics package.json found at /Users/enzomanuelmangano/Desktop/Lavoro/halfy_app/node_modules/#react-native-firebase/analytics/package.json
:#react-native-firebase_analytics:version set from package.json: 6.0.3 (6,0,3 - 6000003)
:#react-native-firebase_analytics:android.compileSdk using custom value: 28
:#react-native-firebase_analytics:android.targetSdk using custom value: 28
:#react-native-firebase_analytics:android.minSdk using custom value: 16
:#react-native-firebase_analytics:reactNativeAndroidDir /Users/enzomanuelmangano/Desktop/Lavoro/halfy_app/node_modules/react-native/android
> Configure project :#react-native-firebase_app
:#react-native-firebase_app:firebase.bom using default value: 21.1.0
:#react-native-firebase_app package.json found at /Users/enzomanuelmangano/Desktop/Lavoro/halfy_app/node_modules/#react-native-firebase/app/package.json
:#react-native-firebase_app:version set from package.json: 6.0.3 (6,0,3 - 6000003)
:#react-native-firebase_app:android.compileSdk using custom value: 28
:#react-native-firebase_app:android.targetSdk using custom value: 28
:#react-native-firebase_app:android.minSdk using custom value: 16
:#react-native-firebase_app:reactNativeAndroidDir /Users/enzomanuelmangano/Desktop/Lavoro/halfy_app/node_modules/react-native/android
> Configure project :app
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
> Task :app:processDebugGoogleServices
Parsing json file: /Users/enzomanuelmangano/Desktop/Lavoro/halfy_app/android/app/google-services.j
son
> Task :app:installDebug
12:51:39 V/ddms: execute: running am get-config
12:51:39 V/ddms: execute 'am get-config' on 'emulator-5554' : EOF hit. Read: -1
12:51:39 V/ddms: execute: returning
Installing APK 'app-debug.apk' on '3.7_WVGA_Nexus_One_API_28(AVD) - 9' for app:debug
12:51:39 D/app-debug.apk: Uploading app-debug.apk onto device 'emulator-5554'
12:51:39 D/Device: Uploading file onto device 'emulator-5554'
12:51:39 D/ddms: Reading file permision of /Users/enzomanuelmangano/Desktop/Lavoro/halfy_app/android/app/build/outputs/apk/debug/app-debug.apk as: rw-r--r--
12:51:39 V/ddms: execute: running pm install -r -t "/data/local/tmp/app-debug.apk"
12:51:40 V/ddms: execute 'pm install -r -t "/data/local/tmp/app-debug.apk"' on 'emulator-5554' : EOF hit. Read:
12:51:40 V/ddms: execute: returning
12:51:40 V/ddms: execute: running rm "/data/local/tmp/app-debug.apk"
12:51:40 V/ddms: execute 'rm "/data/local/tmp/app-debug.apk"' on 'emulator-5554' : EOF hit. Read: -1
12:51:40 V/ddms: execute: returning
Installed on 1 device.
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.1.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 4s
192 actionable tasks: 3 executed, 189 up-to-date
info Connecting to the development server...
info Starting the app on "emulator-5554"...
Starting: Intent { cmp=com.halfy_app/.MainActivity }
Android
android/build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 22
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
playServicesVersion = "17.0.0"
androidMapsUtilsVersion = "0.5+"
}
repositories {
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:3.4.2")
classpath 'com.google.gms:google-services:4.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
maven { url 'https://jitpack.io' }
}
}
android/app/build.gradle
apply plugin: "com.android.application"
apply plugin: 'com.google.gms.google-services'
import com.android.build.OutputFile
project.ext.react = [
entryFile: "index.js",
enableHermes: false, // clean and rebuild if changing
]
apply from: "../../node_modules/react-native/react.gradle"
/**
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
* - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
/**
* The preferred build flavor of JavaScriptCore.
*
* For example, to use the international variant, you can use:
* `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
*
* The international variant includes ICU i18n library and necessary data
* allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
* give correct results when using with locales other than en-US. Note that
* this variant is about 6MiB larger per architecture than default.
*/
def jscFlavor = 'org.webkit:android-jsc:+'
/**
* Whether to enable the Hermes VM.
*
* This should be set on project.ext.react and mirrored here. If it is not set
* on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
* and the benefits of using Hermes will therefore be sharply reduced.
*/
def enableHermes = project.ext.react.get("enableHermes", false);
android {
compileSdkVersion rootProject.ext.compileSdkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.halfy_app"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
}
signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
// Caution! In production, you need to generate your own keystore file.
// see https://facebook.github.io/react-native/docs/signed-apk-android.
signingConfig signingConfigs.debug
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// https://developer.android.com/studio/build/configure-apk-splits.html
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02'
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.facebook.react:react-native:+" // From node_modules
implementation 'com.google.firebase:firebase-analytics:17.2.1'
implementation(project(':react-native-maps')){
exclude group: 'com.google.android.gms', module: 'play-services-base'
exclude group: 'com.google.android.gms', module: 'play-services-maps'
}
implementation 'com.google.android.gms:play-services-base:10.0.1'
implementation 'com.google.android.gms:play-services-maps:10.0.1'
if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
project.ext.vectoricons = [
iconFontNames: [ 'MaterialIcons.ttf', 'FontAwesome.ttf' ] // Name of the font files you want to copy
]
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
apply from: file("../../node_modules/#react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
React Native Version: 0.61
I solved that problem erasing that code in android/app/build.gradle
implementation(project(':react-native-maps')){
exclude group: 'com.google.android.gms', module: 'play-services-base'
exclude group: 'com.google.android.gms', module: 'play-services-maps'
}
implementation 'com.google.android.gms:play-services-base:10.0.1'
implementation 'com.google.android.gms:play-services-maps:10.0.1'
I am using sbt, sbt-native-packager and sbt-proguard to make packages for 3 environments such as dev, staging and production environments. What I would like to do is to be able to specify whether or not to use proguard to make a package. For example, the following command make package using proguard:
$ sbt -Dforceobfuscate=true -Denv=dev rpm:pakageBin
but the following command make package without proguard
$ sbt -Denv=dev rpm:packageBin
What I tried two setting. One is overriding task by system property condition and two is overriding task with dynamic task.
1.Just overriding task by system property.
ProguardKeys.proguard in Proguard := {
if (sys.props.get("forceobfuscate").isDefined) {
( ProguardKeys.proguard in Proguard ).value
} else {
Seq(new File("dummy"))
}
}
This setting always run proguard task (I don't know why).
Also I tried the following setting for just making sure overriding task can stop task.
ProguardKeys.proguard in Proguard := {
if (sys.props.get("forceobfuscate").isDefined) {
// ( ProguardKeys.proguard in Proguard ).value
Seq(new File("dummy"))
} else {
Seq(new File("dummy"))
}
}
Indeed, above setting always skip proguard task.
2.Overriding task using dynamic task.
def obfuscateOrNot = Def.taskDyn {
if (sys.props.get("forceobfuscate").isDefined) {
Def.task {
( ProguardKeys.proguard in Proguard ).value
}
} else {
Def.task {
Seq(new File("dummy"))
}
}
}
ProguardKeys.proguard in Proguard := {
obfuscateOrNot.value
}
Then run the command:
$ sbt rpm:packageBin
Okay, this time skip proguard task. But when I run the command:
$ sbt -Dforceobfuscate=true rpm:packageBin
I got the following error:
sbt.Init$RuntimeUndefined: References to undefined settings at runtime.
sbt.Init$RuntimeUndefined: References to undefined settings at runtime.
setting(ScopedKey(Scope(Select(ProjectRef(file:/work/backend/,backend)),Select(ConfigKey(proguard)),Global,Global),proguard)) at RangePosition(/work/backend/build.sbt,LineRange(244,247)) referenced from ScopedKey(Scope(Select(ProjectRef(file:/work/backend/,backend)),Select(ConfigKey(proguard)),Global,Global),proguard)
at sbt.Init$class.sbt$Init$$handleUndefined(Settings.scala:511)
at sbt.Init$$anon$4.apply(Settings.scala:516)
at sbt.Init$$anon$4.apply(Settings.scala:516)
at sbt.$tilde$greater$$anon$6.apply(TypeFunctions.scala:39)
at sbt.$tilde$greater$$anon$6.apply(TypeFunctions.scala:39)
at sbt.std.FullInstance$$anonfun$flatten$1$$anonfun$apply$3.apply(TaskMacro.scala:51)
at sbt.std.FullInstance$$anonfun$flatten$1$$anonfun$apply$3.apply(TaskMacro.scala:51)
at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
at sbt.std.Transform$$anon$4.work(System.scala:63)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
at sbt.Execute.work(Execute.scala:237)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
[error] (proguard:proguard) sbt.Init$RuntimeUndefined: References to undefined settings at runtime.
[error] setting(ScopedKey(Scope(Select(ProjectRef(file:/work/backend/,backend)),Select(ConfigKey(proguard)),Global,Global),proguard)) at RangePosition(/work/backend/build.sbt,LineRange(244,247)) referenced from ScopedKey(Scope(Select(ProjectRef(file:/work/backend/,backend)),Select(ConfigKey(proguard)),Global,Global),proguard)
[error] Total time: 1 s, completed 2017/07/29 12:09:24
I think the error says that there is no setting for proguard but I am not sure how to set setting using dynamic task.
I would like to make above commands work well. Any solution is fine.
I found a solution. The solution is making proguard Seq[Setting[_]] value depending on condition.
lazy val customProguardSettings =
if (sys.props.get("forceobfuscate").isDefined) {
proguardSettings ++ Seq( ... )
} else {
Nil
}
customProguardSettings
I'm trying to define a jar task for all sub projects (about 30). I tried the following task:
jar {
destinationDir = file('../../../../_temp/core/modules')
archiveName = baseName + '.' + extension
metaInf {
from 'ejbModule/META-INF/' exclude 'MANIFEST.MF'
}
def manifestClasspath = configurations.runtime.collect { it.getName() }.join(',')
manifest {
attributes("Manifest-Version" : "1.0",
"Created-By" : vendor,
"Specification-Title" : appName,
"Specification-Version" : version,
"Specification-Vendor" : vendor,
"Implementation-Title" : appName,
"Implementation-Version" : version,
"Implementation-Vendor" : vendor,
"Main-Class" : "com.dcx.epep.Start",
"Class-Path" : manifestClasspath
)
}
}
My problem is, that the dependencies between the sub projects are not included in the manifest's classpath. I tried changing the runtime configuration to a compile configuration but that results in the following error.
What went wrong: A problem occurred evaluating project ':EskoordClient'.
You can't change a configuration which is not in unresolved state!
That is my complete build file for project EskoordClient:
dependencies {
compile project(':ePEPClient')
}
Most of my sub projects build files only define the projects dependencies. 3rd party lib dependencies are defined in the build file of the super project.
Is there a possibility to include all needed classpath entries (3rd party libraries and other projects) to a manifest classpath in a superproject for all subprojects.
This is how I got it to work. Get Project dependencies only using the call:
getAllDependencies().withType(ProjectDependency)
then adding the contents of each project's libsDir to my Class-Path manifest entry.
jar {
manifest {
attributes 'Main-Class': 'com.my.package.Main'
def manifestCp = configurations.runtime.files.collect {
File file = it
"lib/${file.name}"
}.join(' ')
configurations.runtime.getAllDependencies().withType(ProjectDependency).each {dep->
def depProj = dep.getDependencyProject()
def libFilePaths = project(depProj.path).libsDir.list().collect{ inFile-> "lib/${inFile}" }.join(' ')
logger.info"Adding libs from project ${depProj.name}: [- ${libFilePaths} -]"
manifestCp += ' '+libFilePaths
}
logger.lifecycle("")
logger.lifecycle("---Manifest-Class-Path: ${manifestCp}")
attributes 'Class-Path': manifestCp
}
}
In gradle - how can I embed jars inside my build output jar in the lib
directory (specifially the lib/enttoolkit.jar and lib/mail.jar)?
If you have all the jars inside a directory (lets call it libs) in your project, you only need this:
jar {
into('lib') {
from 'libs'
}
}
I guess it is more likely that these jars are dependencies of some sort. Then you could do it like this:
configurations {
// configuration that holds jars to copy into lib
extraLibs
}
dependencies {
extraLibs 'org.something:something-dep1:version'
extraLibs 'org.something:something-dep2:version'
}
jar {
into('lib') {
from configurations.extraLibs
}
}
Lifted verbatim from: http://docs.codehaus.org/display/GRADLE/Cookbook#Cookbook-Creatingafatjar
Gradle 0.9:
jar {
from configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
Gradle 0.8:
jar.doFirst {
for(file in configurations.compile) {
jar.merge(file)
}
}
The above snippets will only include the compile dependencies for that project, not any transitive runtime dependencies. If you also want to merge those, replace configurations.compile with configurations.runtime.
EDIT: only choosing jars you need
Make a new configuration, releaseJars maybe
configurations {
releaseJars
}
Add the jars you want to that configuration
dependencies {
releaseJars group: 'javax.mail', name: 'mail', version: '1.4'
//etc
}
then use that configuration in the jar task outlined above.
simple:
task copyToLib( type: Copy ) {
into "$buildDir/libs/lib"
from configurations.runtime
}
jar { dependsOn copyToLib }
run it:
$ gradle jar
...
$ tree build/libs
build/libs
├── your-project-0.0.1.BUILD-SNAPSHOT.jar
└── lib
├── akka-actor-2.0.jar
├── akka-camel-2.0.jar
├── ... ... ...
├── spring-expression-3.1.0.RELEASE.jar
└── zmq-2.1.9.jar
1 directory, 46 files
I also needed to do something similar and wasn't quite able to get what Guus and stigkj suggested working, but got close enough with their help to get this working (Guus' example blew up on the dependencies { compile { extendsFrom myLibs }} closure for me.
apply plugin: 'groovy'
repositories {
mavenCentral()
}
configurations {
// custom config of files we want to include in our fat jar that we send to hadoop
includeInJar
}
dependencies {
includeInJar 'org.codehaus.groovy:groovy:1.8.6'
configurations.compile.extendsFrom(configurations.includeInJar)
}
jar {
into('lib') {
println "includeInJar: " + configurations.includeInJar.collect { File file -> file }
from configurations.includeInJar
}
}
Then running gradle jar and examining the created jar gives me this output, showing that I get the jar file to have groovy as well as all jars that it's dependent on inside the "fat jar":
% gradle jar
includeInJar: [/Users/tnaleid/.gradle/caches/artifacts-8/filestore/org.codehaus.groovy/groovy/1.8.6/jar/553ca93e0407c94c89b058c482a404427ac7fc72/groovy-1.8.6.jar, /Users/tnaleid/.gradle/caches/artifacts-8/filestore/antlr/antlr/2.7.7/jar/83cd2cd674a217ade95a4bb83a8a14f351f48bd0/antlr-2.7.7.jar, /Users/tnaleid/.gradle/caches/artifacts-8/filestore/asm/asm/3.2/jar/9bc1511dec6adf302991ced13303e4140fdf9ab7/asm-3.2.jar, /Users/tnaleid/.gradle/caches/artifacts-8/filestore/asm/asm-tree/3.2/jar/cd792e29c79d170c5d0bdd05adf5807cf6875c90/asm-tree-3.2.jar, /Users/tnaleid/.gradle/caches/artifacts-8/filestore/asm/asm-commons/3.2/jar/e7a19b8c60589499e35f5d2068d09013030b8891/asm-commons-3.2.jar, /Users/tnaleid/.gradle/caches/artifacts-8/filestore/asm/asm-util/3.2/jar/37ebfdad34d5f1f45109981465f311bbfbe82dcf/asm-util-3.2.jar, /Users/tnaleid/.gradle/caches/artifacts-8/filestore/asm/asm-analysis/3.2/jar/c624956db93975b7197699dcd7de6145ca7cf2c8/asm-analysis-3.2.jar]
:compileJava UP-TO-DATE
:compileGroovy UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar
BUILD SUCCESSFUL
Total time: 3.387 secs
% jar tvf build/libs/gradletest.jar
0 Mon Mar 12 11:40:00 CDT 2012 META-INF/
25 Mon Mar 12 11:40:00 CDT 2012 META-INF/MANIFEST.MF
0 Mon Mar 12 11:40:00 CDT 2012 lib/
5546084 Mon Mar 05 13:13:32 CST 2012 lib/groovy-1.8.6.jar
445288 Mon Mar 05 13:13:38 CST 2012 lib/antlr-2.7.7.jar
43398 Mon Mar 05 13:13:40 CST 2012 lib/asm-3.2.jar
21878 Mon Mar 05 13:13:40 CST 2012 lib/asm-tree-3.2.jar
33094 Mon Mar 05 13:13:40 CST 2012 lib/asm-commons-3.2.jar
36551 Mon Mar 05 13:13:40 CST 2012 lib/asm-util-3.2.jar
17985 Mon Mar 05 13:13:40 CST 2012 lib/asm-analysis-3.2.jar
Below code could be tried. It depends on the jar task and is of Type Jar
task createJobJar(dependsOn:jar,type:Jar) {
manifest {
attributes(
"Implementation-Title": 'Job '
,"Implementation-Version": version
)
}
classifier 'job'
destinationDir new File("$buildDir")
into('libs'){
from configurations.compile
}
into('classes'){
from "$buildDir/classes"
}
into('resources'){
from "$projectDir/src/main/resources"
}
into('scripts'){
from "$projectDir/src/main/scripts"
}
}
The above code would pack different content inside different directories.
Tested on gradle 2.2
I needed to the same thing you asked, and used this method. you may not need a custom configuration declaration, but i needed to separate the locally used jar files from those declared in a super-build file.
configurations{
//declare custom config if necessary, otherwise just use compile
myLibs
}
dependencies {
//add lib/*.jar files to myLibs
myLibs fileTree(dir: 'lib', include: '*.jar')
compile {
//set compile configuration to extend from myLibs
extendsFrom myLibs
}
}
// task to copy libs to output/lib dir
task copyToLib(type: Copy) {
into "$buildDir/output/lib"
from configurations.myLibs
}
jar {
//include contents of output dir
from "$buildDir/output"
manifest {
//...
}
}
//set build task to depend on copyToLib
build.dependsOn(copyToLib)
I had the same problem. I solved it like this:
Copy the files into the lib folder with copyToLib and reference the dependency with the Class-Path
ext.mainClass = 'test.main'
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.code.gson:gson:2.8.2'
//....
}
jar {
from "$buildDir/libs/lib"
manifest {
attributes 'Main-Class': 'test.main',
'Class-Path': configurations.compile.collect { 'lib/'+it.getName() }.join(' ')
}
}
task copyToLib(type: Copy) {
into "$buildDir/libs/lib"
from configurations.compile
}
build.dependsOn(copyToLib)
In my case I needed to include a contents of the root project Jar into subproject Jar. So, to make it work, one can use this template:
jar{
manifest{
attributes 'Main-Class':'<main class>'
}
def conf= configurations.find {it.name.equals('compile') }
File jar= conf.files.find {it.name.contains('<name or part of the name of produced Jar>')}
FileTree fileTree=zipTree(jar)
from fileTree
}
My example:
jar{
manifest{
attributes 'Main-Class':'alexiy.jace.Jace'
}
description='Make a runnable API Jar'
def conf= configurations.find {it.name.equals('compile') }
File tools= conf.files.find {it.name.contains('Tools')}
FileTree fileTree=zipTree(tools)
from fileTree
}
Here's how I managed to achieve this build setting using Gradle. This will build your app into a Jar, copy the library jars generated into the libs directory under build/libs and also configure classpath to include the jars in the created build/libs/libs directory.
plugins {
id 'application'
}
group 'org.pkg'
version '1.0-SNAPSHOT'
ext.mainClass = 'org.pkg.MainClass'
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile group: 'junit', name: 'junit', version: '4.12'
implementation group: 'com.mchange', name: 'c3p0', version: '0.9.5.5'
}
task copyToLib(type: Copy) {
into "$buildDir/libs/libs"
// configurations.runtimeClasspath includes maven jars
from configurations.runtimeClasspath
}
def archiveVersion = "1.0.0"
task uberJar(type: Jar) {
archiveClassifier = 'uber'
from sourceSets.main.output
// include the copy task
dependsOn(copyToLib)
// use onfigurations.runtimeClasspath to collect all the jars
manifest {
attributes(
'Class-Path': configurations.runtimeClasspath.collect { 'libs/' + it.getName() }.join(' '),
'Main-Class': 'org.pkg.MainClass',
"Implementation-Title": "Gradle",
"Implementation-Version": archiveVersion
)
}
}
task <taskname>(type: Jar) {
archiveName 'nameofjar.jar'
doFirst {
manifest {
attributes 'Class-Path': configurations.compile.files.collect{ project.uri(it) }.join(' ')
}
}
}