My Gradle project depends on commons-io 2.4, but Gradle puts $GRADLE_HOME/commons-io-1.4.jar into the classpath, causing failures - groovy

I've been iterating on features in my first Gradle plugin. I determined early on that I needed commons-io, so I added a dependency on commons-io 2.4, being the latest version.
This has been going well for a while, with the build working from the command line, and no errors in Eclipse.
I just started trying to integrate some code that uses "FileUtils.write(File,String)". I didn't need that method before. I got everything un-redded in Eclipse, and then I tried a command line build.
This failed with errors like the following:
... error: cannot find symbol
FileUtils.write(serviceLoaderFile,
^
symbol: method write(File,String)
location: class FileUtils
This confused me. I went to the failing lines in Eclipse, and no issues were indicated. I navigated into the "write()" method, and it looked fine to me. I then ran my command-line build with "--debug" to get some clues.
When I found the "javac" line, I found that "$GRADLE_HOME\lib\commons-io-1.4.jar" (where "GRADLE_HOME" is just my Gradle 2.3 distribution) was in the classpath BEFORE my dependency jar. I then inspected the code in the 1.4 jar, and I determined that the "FileUtils" class in that version didn't have a "write" method.
What am I supposed to do about this?
Update:
I suppose it's likely my "dependencies" block would be useful, which is this:
dependencies {
compile ("org.codehaus.groovy:groovy-all:2.3.9")
compile gradleApi()
compile "org.opendaylight.yangtools:yang-parser-impl:0.7.0-SNAPSHOT"
compile "org.opendaylight.yangtools:binding-java-api-generator:0.7.0-SNAPSHOT"
compile "org.opendaylight.yangtools:binding-generator-api:0.7.0-SNAPSHOT"
compile "org.opendaylight.yangtools:binding-generator-impl:0.7.0-SNAPSHOT"
compile "org.opendaylight.controller:yang-jmx-generator:0.3.0-SNAPSHOT"
compile "commons-io:commons-io:2.4"
testCompile("org.spockframework:spock-core:1.0-groovy-2.3") {
exclude group: "org.codehaus.groovy"
}
I tried commenting out the "gradleApi" reference, and that had no effect. I also tried adding an "exclude" for commons-io associated with the "groovy-all" reference, but that also didn't appear to make any difference.
}

You probably added gradleApi() under dependencies {} block - see the docs. The problem is that it ships all dependencies gradle requires - including commons-io in version 1.4 - see the extract below:
[opal#opal-mac-2]~/.gvm/gradle/current/lib % pwd
/Users/opal/.gvm/gradle/current/lib
[opal#opal-mac-2]~/.gvm/gradle/current/lib % ll commons-io-1.4.jar
-rw-rw-r-- 1 opal staff 109043 23 gru 13:17 commons-io-1.4.jar
[opal#opal-mac-2]~/.gvm/gradle/current/lib %
You probably added version 2.4 separately and that's why conflict occurred. You can also run
gradle dependencies
to view the full dependency tree and verify the problem.
There's no possibility to exclude a transitive dependency from gradleApi().

The solution to this required adding the following block to the "sourceSets" block:
main {
compileClasspath = configurations.compile.minus files("$gradle.gradleHomeDir/lib/commons-io-1.4.jar")
}
This is pretty simple, but I wish there was a cleaner solution for this. I'm not sure what that would look like.

Related

Building the Spock tutorial example fails

I wanted to get going with Haskell a little bit and therefore took a look at the Spock framework. To start clean, I uninstalled everything Haskell related from my Arch Linux machine and installed ghcup, Cabal and Stack using the install scripts from their respective websites.
Now I want to follow Spock's Tutorial. Trying to install Spock globally with cabal install Spock as suggested gives me an error (abbreviated):
src/Web/Spock/Internal/Wire.hs:43:1: error:
Could not find module ‘Web.Routing.AbstractRouter’
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
43 | import Web.Routing.AbstractRouter
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cabal: Failed to build Spock-0.9.0.1. See the build log above for details.
I already found a question on reddit on the topic, but the solution does not apply because I'm not trying to use a specific version of the libraries as implied.
So I try to follow along and build only locally.
But when I reach the point where it says stack build --fast --pedantic, the build plan can not be constructed and Stack suggests to add another dependency, stm-containers. Doing so, I am presented with two additional suggestions for focus and primitive. When I add these, the plan fails again, this time without a simple solution:
In the dependencies for primitive-0.6.4.0:
base-4.13.0.0 from stack configuration does not match >=4.5 && <4.13 (latest matching version is 4.12.0.0)
needed due to Spock-example-0.1.0.0 -> primitive-0.6.4.0
I can do a little thing with Haskell, but with the build system(s), I am way out of my comfort zone. Help and hints appreciated. Oh, and all versions of course are the latest by the time of this post.
Due to incompatible versions of dependencies, Spock won't build with GHC 8.8 and above. A similar problem is described in Spock issue #149, though I'm not fully sure it is exactly the same incompatibility. The error you got from Stack hints at that, as base-4.13.0.0 is the version of base that is bundled with GHC 8.8. cabal-install failed in a more obscure way because, upon noting the incompatibility, it tries to solve the dependencies using older versions of Spock, eventually picking 0.9.0.1, attempting and, thanks to a missing version upper bound for the reroute dependency, failing to build it.
(Shortly after this answer was posted, the missing upper bound was retrofitted to the old Spock version, so attempting to reproduce the problem now will lead to an easier to understand failure.)
Casting the tutorial aside, the most straightforward way to use Spock given those complications is probably through cabal-install 3+. Begin by using ghcup to switch to GHC 8.6.5:
$ ghcup install 8.6.5
$ ghcup set 8.6.5
Then, create a blank project with cabal-install:
$ mkdir myproject
$ cd myproject
$ cabal init
Add Spock to the build-depends section of myproject.cabal:
build-depends: base >=4.12 && <4.13
, Spock == 0.13.*
Finally, you can run:
$ cabal build
Which will install Spock and its dependencies before building the project. (Note that you generally don't need to use cabal install to install libraries with cabal-install 3.)
It is presumably possible to make it work with Stack as well, by changing to the lts-14.27 resolver (the latest one that uses GHC 8.6.5), tracking down all dependency versions that need to be overriden (as you had began to do) and manually adding them to the extra-deps of stack.yaml.

Ionic Android : Error of version conflict of gcm services while adding FCM plugin

Execution failed for task ':processDebugGoogleServices'.
Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 9.0.0.
In case of Cordova OR Ionic App
I have the similar problem with my ionic 1 cordova build after Integrating the Firebase Cloud Messaging ( FCM )
Error Message
What went wrong:
Execution failed for task ':processDebugGoogleServices'.
Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 9.0.0.
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 1.605 secs
Error: /Users/beo-administrator/Documents/projects/Apps/Ionic/psc/platforms/android/gradlew: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':processDebugGoogleServices'.
Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 9.0.0.
Solution
I fixed this issue by the following steps
So one fix will be: inside platforms/android open project.properties (Its a file ) , you will have something like this
cordova.system.library.1=com.google.android.gms:play-services-ads:+
cordova.system.library.2=com.google.firebase:firebase-core:+
cordova.system.library.3=com.google.firebase:firebase-messaging:+
Replace the
+
Sign with your target version number - like the following
cordova.system.library.1=com.google.android.gms:play-services-ads:9.0.0
cordova.system.library.2=com.google.firebase:firebase-core:9.0.0
cordova.system.library.3=com.google.firebase:firebase-messaging:9.0.0
Save the file
Then take build using
ionic cordova run android
Go to platforms > android > android build.gradle and add below three lines in dependencies area
compile "com.google.firebase:firebase-core:9.0.0"
compile "com.google.firebase:firebase-messaging:9.0.0"
compile "com.google.android.gms:play-services-gcm:9.0.0"
Now your update dependencies looks like as-
dependencies {
compile fileTree(include: '*.jar', dir: 'libs')
// SUB-PROJECT DEPENDENCIES START
debugCompile project(path: 'CordovaLib', configuration: 'debug')
releaseCompile project(path: 'CordovaLib', configuration: 'release')
compile 'com.android.support:support-v4:23.4.0'
compile 'com.facebook.android:facebook-android-sdk:4.14.+'
// compile 'com.google.firebase:firebase-core:+'
// compile 'com.google.firebase:firebase-messaging:+'
// SUB-PROJECT DEPENDENCIES END
compile files('libs/twitter4j-core-4.0.2.jar')
compile 'com.google.code.gson:gson:2.8.0'
compile "com.google.firebase:firebase-core:9.0.0"
compile "com.google.firebase:firebase-messaging:9.0.0"
compile "com.google.android.gms:play-services-gcm:9.0.0"
}
Go to platforms > android > cordova-plugin-fcm. Find file that look like something-FCMPlugin.gradle.
Then change to:
buildscript {
repositories {
jcenter()
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:+'
classpath 'com.google.gms:google-services:3.0.0' // change this line
}
}
// apply plugin: 'com.google.gms.google-services'
// class must be used instead of id(string) to be able to apply plugin from non-root gradle file
apply plugin: com.google.gms.googleservices.GoogleServicesPlugin
source:
https://stackoverflow.com/a/44039853/8037833
Had the same problem and the other answers didn't work for me.(as on build the build.gradle get's edited and the version nr return to the previous nr.)
I've fixed it by editing the project.properties file in platforms/android/
target=android-25
android.library.reference.1=CordovaLib
cordova.gradle.include.1=com-sarriaroman-photoviewer/starter-photoviewer.gradle
cordova.system.library.1=com.android.support:support-v4:24.1.1+
cordova.system.library.2=com.android.support:support-v13:25.1.0
cordova.system.library.3=me.leolin:ShortcutBadger:1.1.17#aar
cordova.system.library.4=com.google.firebase:firebase-messaging:11.0.1
cordova.gradle.include.2=phonegap-plugin-push/starter-push.gradle
cordova.system.library.5=com.google.android.gms:play-services-base:11.0.1
cordova.system.library.6=com.google.android.gms:play-services-ads:11.0.1
Make sure that there is the same version of com.google.android.gms

Android Studio update 1.0 breaks NDK compilation

I just updated from 0.8.14 to 1.0 RC4 and now my NDK support seems broken.
The failing ndk-build call:
C:\Users\layer0\AppData\Local\Android\android-ndk32-r10b-windows-x86_64\ndk-build.cmd NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=C:\Users\layer0\AndroidStudioProjects\GameEngine\app\build\intermediates\ndk\debug\Android.mk APP_PLATFORM=android-20
NDK_OUT=C:\Users\layer0\AndroidStudioProjects\GameEngine\app\build\intermediates\ndk\debug\obj NDK_LIBS_OUT=C:\Users\layer0\AndroidStudioProjects\GameEngine\app\build\intermediates\ndk\debug\lib APP_ABI=all
Error message from make:
make.exe: *** No rule to make target C:\Users\layer0\AndroidStudioProjects\GameEngine\app\build\intermediates\ndk\debug\obj/local/armeabi-v7a/objs/my-jni/C_\Users\layer0\AndroidStudioProjects\GameEngine\app\src\main\jni',
needed by C:\Users\layer0\AndroidStudioProjects\GameEngine\app\build\intermediates\ndk\debug\obj/local/armeabi-v7a/objs/my-jni/C_\Users\layer0\AndroidStudioProjects\GameEngine\app\src\main\jni\buffercopies.o'. Stop.
The whole project, including the JNI parts was compiling fine just hours ago before the update. I guess something changed in the configs or about the supported ABIs?
But i don't really know what to look for.
Write it down, think, try again ... find a solution. grrrr
Effect was this bug:
https://code.google.com/p/android/issues/detail?id=66937
Issue 66937: "no rule to make target" when compiling only one .c file with ndk-build.cmd launched from gradle
Once the .so files are created the dummy.c file can be removed. I did that and forgot about the bug, so it came back after the update.

Exclude some compile dependencies for runtime in Gradle

I am using Gradle to build my Groovy application. As usual I specify the compile dependencies in the build.gradle script, like this:
dependencies {
// groovy
compile "org.codehaus.groovy:groovy:$groovyVersion"
compile "org.codehaus.groovy:groovy-json:$groovyVersion"
compile "org.codehaus.groovy:groovy-test:$groovyVersion"
// some more external dependencies...
}
Ok, for runtime I don't need all of these dependencies, for example I don't need any testing classes. So what I am looking for now is a way to tell Gradle that it should use the same dependencies for runtime as for compile (which is the default anyway), but excluding some of them.
Is there a short way to achieve that, or do I have to list all dependencies for runtime as well?
It's the other way around: Groovy's transitive dependencies aren't normally required for compilation (except that due to a known limitation of the Groovy compiler, they sometimes are), but they are definitely needed at runtime. However, it's not worthwhile to optimize compile dependencies here, so just keep declaring Groovy dependencies as compile dependencies (which automatically makes them runtime dependencies as well). Groovy test dependencies should be added to the testCompile configuration.

Ant LibusbJava compile error: "jni.h: No such file"...fixed, now a memset error

There appears to be a Ant / jni.h problem (for my setup) with LibusbJava. I get the following error when setting up LibusbJava by running
ant linux
in CentOS 6.3 as root (quick and dirty test, thanks for those concerned about user level =0). I will redo with proper restrictions as shown on a libusbjava reference after reflection when first install works. LibusbJava, is a Java wrapper for the libusb library.
The output starts out like this:
[root#somebox LibusbJava]# ant linux -lib $JAVA_HOME/include -lib $JAVA_HOME/include/linux
Buildfile: build.xml
clean:
Build LibusbJava Test Linux:
Build LibusbJava Test:
[echo] Building Library for unit tests:
[exec] /.../libusbjava/trunk/LibusbJava/LibusbJava.cpp:27:17: error: jni.h: No such file or directory
[exec] /.../libusbjava/trunk/LibusbJava/LibusbJava.cpp:34:26: error: test/CuTest.h: No such file or directory
`...`
as it was not set on my system. It appears that jni.h is a header called by C++ code, which I had to add to the LibusbJava.cpp file. This is the new include, /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.9.x86_64/include/jni.h. I then get an error with jni.h not being able to fine jni_md.h which is an include in jni.h #include "jni_md.h".
Clearly this is not the right approach, so perhaps I need a correct Ant reference, but I cannot seem to do it with a -lib switch. Besides, this just creates thousands of jni.h file errors during the Ant build attempt.
How can I fix this problem?
Notes: I've set$JAVA_HOME up like JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.9.x86_64 and javac and java work fine.
New discovery... after helpful questions which guided me, I am much closer to successful compilation.
When I install LibusbJava and manually install all the library references in build.xml there is still an error compiling the LibusbJava based on a memset error. I see memset patches for libusb that appeared in 2007 and it's unclear how to use or if they relate. Investigating... Hints, comments and questions welcome. My most sincere thanks for the help thus far.
[exec] /.../libu/libusbjava/trunk/LibusbJava/objects/Usb_Device.cpp: In function ‘void Usb_Device_disconnect(JNIEnv*)’:
[exec] /.../libu/libusbjava/trunk/LibusbJava/objects/Usb_Device.cpp:88: error: ‘memset’ was not declared in this scope
[antcall] Exiting /.../libu/libusbjava/trunk/LibusbJava/build.xml.
BUILD FAILED
but I find no referece to an include string.h or cstring. The header of Usb_Device.cpp mentions it is a C++ Stub for the java class of a java class ch.ntb.inf.libusbJava.Usb_Device. which only has this include #include "Usb_Device.h" which also does not appear to have a string include. Perhaps just insertion of#include`?

Resources