custom library from maven not able to download for different version - java

I have a custom library uploaded to bintray maven with version 1.0.0
To download it for any project i have used the following code
repositories {
maven {
url "http://dl.bintray.com/<org or user name>/<repo-name>"
}
}
And inside my app level build.gradle i have added the dependency
dependencies {
.....
compile 'my-group-id:artifactId:versionId'
.....
}
Recently i upgraded the versionId to 1.0.2 and it doesn't compile. For version 1.0.0 it compiles fine.
Heres the error i get
Error: Could not find sdk.jar (com.appunfold:sdk:1.0.2).
Searched in the following locations:
http://dl.bintray.com/appunfold/android/com/appunfold/sdk/1.0.2/sdk-1.0.2.jar
I checked the files inside 1.0.2. It contains sdk-1.0.2.aar (not sdk-1.0.2.jar)and compared it with the files inside 1.0.0. It contains the same with the version 1.0.0 i,e sdk-1.0.0.aar.
I couldn't find the reason why it is not able to download for a different version. Anybody faced the same issue?

Found the solution after a deep few hours of research.
I think Android Studio by default searches for jar files. But since in my case only aar files are available i had to specify one more parameter (#aar) while compiling the dependency.
It looks like this
dependencies {
.....
compile 'my-group-id:artifactId:versionId:#aar'
.....
}

Related

Using Java & Gradle to build a maven project from github

I need help with the following problem:
Right now, I want to use my Java Gradle Project to build this github-project:
https://github.com/PaperMC/Paper but the project but it's a maven project.
I found a plugin for adding github projects as dependencies but it fails here.
An alternative would be to use this jenkins here: https://ci.destroystokyo.com/job/Paper/
However here I'm struggling to make my gradle always use the newest build without having to reasign the chaning version numbers by hand.
Can someone help me out because I have no idea what and how to add to the build.gradle.
Thanks in advance!
Edit:
I found the Maven-Syntax for the correct pull here:
https://paper.readthedocs.io/en/paper-1.11/developers/#plugin-developers
But when I try to convert the information to Gradle I still fail when I try to leave out the version so that Gradle would fetch the latest one. Can someone provide a valid snipped for this? I have never done this before.
According to this guy, you can use a fake ivy repository.
As https://ci.destroystokyo.com/job/Paper/lastSuccessfulBuild/artifact/paperclip.jar points on the latest build, just set up your repository like this :
repositories {
ivy {
url "https://ci.destroystokyo.com/job/Paper/lastSuccessfulBuild/artifact/"
layout 'pattern' , {
ivy '[module]-ivy.xml'
artifact '[module](.[ext])'
}
}
}
And then, use the dependency (the group is not relevant here)
dependencies {
compile 'anything:paperclip'
}
It will get the right file
$ gradle build
Download https://ci.destroystokyo.com/job/Paper/lastSuccessfulBuild/artifact/paperclip.jar
...

Why does Gradle resolve a package with wrong version number?

I am building a web application and I am using Dropwizard 1.3.0, which has a dependency on jetty-io 9.4.8. This dependency has conflicts with another package (dropwizard-websocket-jee7-bundle 2.0.0), because it seem to fetch the wrong version number.
I looked into tha package, and found the method that has been renamed in 9.4.x - AbstractWebSocketConnection.java from 9.3.x - AbstractWebSocketConnection.java. The issue is that even though in Gradle the dependency tree shows I fetched 9.4.8 (the new one which I need), I still get the older, 9.3.x java file which causes the conflicts. I tried to Invalidate Caches / Restart and rebuild the whole project, but I seem to get the outdated file all the time.
What are the possible solutions for this?
If your bad class are imported by a transitive dependency, try to exclude explicit the transitive dependency.
For example if your required library is 'my.group:requiredLibrary:2.0.0' and there are another version in 'my.group:someDependency:0.1.5' you can do like this:
dependencies{
compile 'my.group:requiredLibrary:2.0.0'
compile ('my.group:someDependency:0.1.5'){
exclude group: 'my.group' module:'requiredLibrary'
}
}
Try forcing a particular version in your build.gradle
Example here: https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html

Get latest snapshot version from Maven Repository in Gradle

I have project which using Gradle to publish our SNAPSHOT artifact's to remote Maven Repository.
When I publish to Maven, time stamp and build number is getting appended to Jar name. And I am trying to download the latest version ie myjar-1.6.0-20170926.190543-10.jar from one of other project. I am not able to download until unless, I remove it from my .gradle or restart my work space.
myjar-1.6.0-20170926.162756-7.jar
myjar-1.6.0-20170926.162756-7.jar.md5
myjar-1.6.0-20170926.162756-7.jar.sha1
myjar-1.6.0-20170926.162756-7.pom
myjar-1.6.0-20170926.162756-7.pom.md5
myjar-1.6.0-20170926.162756-7.pom.sha1
myjar-1.6.0-20170926.182639-8.jar
myjar-1.6.0-20170926.182639-8.jar.md5
myjar-1.6.0-20170926.182639-8.jar.sha1
myjar-1.6.0-20170926.182639-8.pom
myjar-1.6.0-20170926.182639-8.pom.md5
myjar-1.6.0-20170926.182639-8.pom.sha1
myjar-1.6.0-20170926.182748-9.jar
myjar-1.6.0-20170926.182748-9.jar.md5
myjar-1.6.0-20170926.182748-9.jar.sha1
myjar-1.6.0-20170926.182748-9.pom
myjar-1.6.0-20170926.182748-9.pom.md5
myjar-1.6.0-20170926.182748-9.pom.sha1
myjar-1.6.0-20170926.190543-10.jar
myjar-1.6.0-20170926.190543-10.jar.md5
myjar-1.6.0-20170926.190543-10.jar.sha1
myjar-1.6.0-20170926.190543-10.pom
myjar-1.6.0-20170926.190543-10.pom.md5
myjar-1.6.0-20170926.190543-10.pom.sha1
The dependency project has below
configurations.all {
resolutionStrategy.cacheDynamicVersionsFor 0, 'seconds'
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
compile ( group: "com.test", name:"myjar", version: "1.6.0-SNAPSHOT", changing: true );
Also tried with
compile ( "com.test:myjar:latest.integration);
But nothing working out. Let me know how to fix this?
You can run the local build with --refresh-dependencies. See the answers to this question How can I force gradle to redownload dependencies? for more information.
I encounter the same situation as you.
Develop environment: Android Studio 4.0
Building tools: gradle 3.6
Computer: Mac
I'm at app end, while I am using a jar from server end, the jar is included by adding maven repo and adding project dependency in build.gradle, like this:
buildscript {
repositories {
mavenLocal()
maven { url 'http://maven.xxx.com/xxx/xxx/‘ }
}}
dependencies {
...
implementation ‘project_group_id:artifact_id:latest.integration’
}
Instead of using ./gradlew build --refresh-dependencies to clear cache, I directly went to the cache folder /Users/your_user_name/.gradle/caches/modules-2/files-2.1 and delete the local jar in order to download updated one.
But still failed...
Finally we found the cause is weird:
we included several maven repo, one repo has the same project as the one we need, but it has only one version for each version code.It is in front of the maven repo from which we can download newest jar, therefore it blocked the update of the newest version.
We exchange the sequence of these two repo, and the problem disappear.
In my case, it's nothing to do with the maven config or the cache, it is due to repo included in gradle. Further reason still need to dig.
Hope can help the ones who meet the same problem.

Using jackson-dataformat-xml on android

I'm strugling with using jackson-dataformat-xml on android
I have some very basic code that works fine on oracle jre
JacksonXmlModule module = new JacksonXmlModule();
module.setDefaultUseWrapper(false);
XmlMapper xmlMapper = new XmlMapper(module);
First I tried official documentation adapted for gradle (by me, not sure if done correctly):
compile 'com.fasterxml.jackson.core:jackson-core:2.5.4'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.5.4'
compile 'com.fasterxml.jackson.core:jackson-databind:2.5.4'
compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.5.4'
compile 'org.codehaus.woodstox:woodstox-core-asl:4.4.1'
compile 'javax.xml.stream:stax-api:1.0-2'
Result: gradle fails build time about bundling corelibraries into an application
...
:app:preDexDebug
trouble processing "javax/xml/stream/EventFilter.class":
Ill-advised or mistaken usage of a core class (java.* or javax.*)
when not building a core library.
...
2nd attempt trying to follow Sean's answer
(Basicly he repackages corelibs with prefix names and rebuilds jackson-dataformat-xml to use the prefixed names)
compile 'com.fasterxml.jackson.core:jackson-core:2.1.2'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.1.2'
compile 'com.fasterxml.jackson.core:jackson-databind:2.1.2'
// Repackaged XML-specific libraries
compile 'edu.usf.cutr.android.xml:jackson-dataformat-xml-android:2.1.2'
compile 'edu.usf.cutr.android.xml:stax2-api-android:3.1.1'
compile 'edu.usf.cutr.android.xml:stax-api-android:1.0-2'
compile 'edu.usf.cutr.android.xml:aalto-xml-android:0.9.8'
And build time failed on duplicates
Duplicate files copied in APK META-INF/services/com.fasterxml.jackson.core.ObjectCodec
so added:
packagingOptions {
...
exclude 'META-INF/services/com.fasterxml.jackson.core.JsonFactory'
exclude 'META-INF/services/com.fasterxml.jackson.core.ObjectCodec'
}
When adding the exclusions it builds and deploys, but fails runtime on below stackdump (AFAIK it cant find the SAX provider, even tho it is added to the classpath to my understanding)
edu.usf.cutr.javax.xml.stream.FactoryConfigurationError: Provider com.bea.xml.stream.MXParserFactory not found
at edu.usf.cutr.javax.xml.stream.FactoryFinder.newInstance(FactoryFinder.java:72)
at edu.usf.cutr.javax.xml.stream.FactoryFinder.find(FactoryFinder.java:176)
at edu.usf.cutr.javax.xml.stream.FactoryFinder.find(FactoryFinder.java:92)
at edu.usf.cutr.javax.xml.stream.XMLInputFactory.newInstance(XMLInputFactory.java:136)
at com.fasterxml.jackson.dataformat.xml.XmlFactory.<init>(XmlFactory.java:97)
at com.fasterxml.jackson.dataformat.xml.XmlFactory.<init>(XmlFactory.java:85)
at com.fasterxml.jackson.dataformat.xml.XmlFactory.<init>(XmlFactory.java:82)
at com.fasterxml.jackson.dataformat.xml.XmlMapper.<init>(XmlMapper.java:46)
What is the proper way to move forward on either #1 or #2?
Number 2 is the correct approach (Android doesn't like it when you include classes in the official Java package namespace - but then again, I wrote the original answer so I'm biased ;) ).
I believe the FactoryConfigurationError: Provider com.bea.xml.stream.MXParserFactory not found error is due to a bug in the Android build tools. In previous versions of ADT for Eclipse and Gradle plugin < 0.7.0 the /META-INF/* files are stripped from the JARs during the build process. It seems like >= v0.7.0 shouldn't have the problem according to Google, but from others' reports it sounds like it still may be problematic, and could potentially remove the META-INF/services/javax.xml.stream.XMLInputFactory file, which is required for the platform to register Aalto.
Try the workaround mentioned in AOSP issue 59658 comment 22:
right click on /src/main (where you have /java and /res folders),
select New > Folder > Java Resources Folder,
click Finish (do not change Folder Location),
right click on new /resources folder,
select New > Directory
enter "META-INF" (without quotes),
right click on /resources/META-INF folder,
select New > Directory
enter "services" (without quotes)
copy any file you need into /resources/META-INF/services
For you, in step 10 above you'd need to copy this file into /resources/META-INF/services. In case the file link is broken in the future, the name of the file is javax.xml.stream.XMLInputFactory and it consists of a single line:
com.fasterxml.aalto.stax.InputFactoryImpl
EDIT
If you get a "Error:duplicate files during packaging of APK... Path in archive: META-INF/services/javax.xml.stream.XMLInputFactory", you can try telling Gradle to keep the first occurrence with:
android {
packagingOptions {
pickFirst 'META-INF/services/javax.xml.stream.XMLInputFactory'
}
}
EDIT 2
This bug may be affecting "pickFirst". Please make sure you're running the latest version of Android Studio, and update your local tools and Android Gradle plugin to make sure you're running the most recent version of the tools. This may be fixed in Android Studio 1.3 RC1.
I have attempted to add XmlPull support to jackson xml. Find the forked project here:
https://github.com/finvu/jackson-dataformat-xml
Currently, only supported for version 2.9.6. (clone the branch jackson-dataformat-xml-2.9.6-XmlPull)
Sorry, I am not able to provide detailed documentation due to time constraints. If you have knowledge of git and maven to pull a specific branch and build the jar, then it should be relatively easy.
To those who will be in need of this in the future:
first integrate Jitpack in Your Android app, following their instructions:
https://jitpack.io/
Then paste teh GitHub url of jackson-dataformat-xml on Jitpack sites' corresponding text box. GitHub url is:
https://github.com/FasterXML/jackson-dataformat-xml.
That's it! Enjoy the result. :)

How can you override an existing Gradle plugin from a local repository?

I am building an application using Gradle, JDK 8, Java FX, and Test FX. I need to be on JDK 8 for our application to work on all platforms with our tech stack. My problem is that I am unable to get code coverage into our build. I found this link...
https://github.com/jacoco/jacoco/issues/74
...and using the Jacoco preview build at the top, I was able to replace my intellij JARs and successfully run my tests and get the coverage. However, I am having trouble putting this into my build.gradle. From what I can tell, I need to add a local repository in my build script...
...
apply plugin: "jacoco"
...
buildscript {
repositories {
// Local Repo
// MVN Repo(s)
}
dependencies {
// Classpaths
}
}
jacoco {
toolVersion = "0.6.4.201311160552" // I need this specific version, which isn't on a MVN repo
}
...I tried to add my local repo several ways including...
flatDir(dirs: "lib")
flatDir dirs: "${projectDir}/lib"
maven { url uri("lib") }
one or two other ways I forget
...my lib folder contains the exact contents, unchanged, from the preview build zip's lib folder in the link above. It doesn't seem like gradle is having a problem locating the local repo, but it is having trouble finding the JAR. I assume there is something wrong with the way I am naming it or the way that it is "packaged". I have tried modifying the JAR names but I keep getting the error...
What went wrong:
A problem occurred configuring root project 'myProject'.
Could not resolve all dependencies for configuration ':classpath'.
Could not find :org.jacoco.agent:.
Required by:
:myProject:unspecified
...any ideas why my JAR is not being found? Thanks!
"Answering" my own question, despite the fact that I still haven't quite figured it out. Anyways, here are two links I found that seem to solve my problem...
http://forums.gradle.org/gradle/topics/jacocotestreport_is_skipping
...following some of these instructions allow my tests to run, but I am still not able to run "gradle jacocoTestReport" without it failing.
UPDATE
OKAY! I figured it out, the link above did help me figure it out. My problem was with the asm-all JAR, since there were several, I did not know which one to use. In order to get jacoco working with Java 1.8, you do not need to specify the toolVersion property. All you need to do is add the following to your dependencies block (not the buildscript block, the code block)...
jacocoAgent files(
"$projectDir/lib/org.jacoco.agent-0.6.4.201311160552.jar")
jacocoAnt files(
"$projectDir/lib/org.jacoco.ant-0.6.4.201311160552.jar",
"$projectDir/lib/org.jacoco.core-0.6.4.201311160552.jar",
"$projectDir/lib/org.jacoco.report-0.6.4.201311160552.jar",
"$projectDir/lib/asm-all-5.0_BETA.jar")
...where the asm-all-5.0_BETA.jar is taken from the org.ow2.asm group found at...
http://mvnrepository.com/artifact/org.ow2.asm/asm-all/5.0_BETA
...hope this helps!
for reference, latest jacoco libs are changed so i'm sharing the following snippet:
dependencies{
jacocoAgent files("$rootProject.projectDir/lib/org.jacoco.agent-0.8.3.201904130250.jar")
jacocoAnt files("$rootProject.projectDir/lib/org.jacoco.ant-0.8.3.201904130250.jar",
"$rootProject.projectDir/lib/org.jacoco.core-0.8.3.201904130250.jar",
"$rootProject.projectDir/lib/org.jacoco.report-0.8.3.201904130250.jar",
"$rootProject.projectDir/lib/asm-7.0.jar",
"$rootProject.projectDir/lib/asm-tree-7.0.jar",
"$rootProject.projectDir/lib/asm-commons-7.0.jar"
)
}

Categories

Resources