Gradle dependency NoSuchMethodError 'AnnotationAttributes.getAliasedStringArray' - java

I'm building a sftp upload and download project with spring integration in intellij and i'm having problems with these methods: ObjectUtils.unwrapOptional, AnnotationAttributes.getAliasedStringArray. When i run the project i get the NoSuchMethodError error for one of the methods mentioned above. I'm not finding a spring-core jar that contains both of them, the current jar i'm using in gradle is: 'compile group: org.springframework', name: 'spring-core', version: '5.0.8.RELEASE' which doesn't contain the getAliasedStringArray method at AnnotationAttributes class. Can somebody help me with the version of the jar which contains both methods? Thanks

AnnotationAttributes.getAliasedStringArray was depreciated as of 4.3.6.RELEASE and was replaced by AnnotationAttributes.getStringArray (check out the specification for 5.0.8.RELEASE).
Essentially, you'll either have to change the implemenation to the new method as the deprecated method is not in the version your using or you'll have to down grade your version.

Related

Cannot resolve symbol 'JsonException' - Json Simple import problem

I want to use Json simple in my project, however I can't get it to work. I tried versions 1.1.0, 3.1.0, 3.1.3, 4.0.0 and every time I do import com.github.cliftonlabs.json_simple.JsonException; I have error Cannot resolve symbol 'JsonException' I use InteliJ, every time I tried a version I went to File> Project Structure and added .jar file. Then I add dependecy compile group: 'com.github.cliftonlabs', name: 'json-simple', version: '3.1.0' into my build.gradle. The error repeats every time. How do I fix this?
I managed to fix the issue, I used
implementation 'com.github.cliftonlabs:json-simple:4.0.0' in build.gradle
and refreshed the gradle build

Including javax persistence in a Cordova/Android project

I am trying to incorporate ObjectBox in my hybrid Cordova/Android project. By dint of some trial and error I have managed to figure out two of the steps involved.
The app level build.gradle file has to be modified to include the ObjectBox Gradle plugin classpath "io.objectbox:objectbox-gradle-plugin:2.5.0"
Define a build-extras.gradle file to "apply" the ObjectBox plugin ext.postBuildExtras = {apply plugin: 'io.objectbox'}
The next step according to the ObjectBox docs is to define at least one Entity class
However, the issue here is that I need to import the javax.persistence.* classes into the project. It is not clear to me how I do this. I have run into suggestions along the lines of including
compile group: 'javax.persistence', name: 'javax.persistence-api', version: '2.2'
in the dependencies section of the app level build.gradle file. However, this causes gradle to complain that it does not know the compile() function. I'd be much obliged to anyone who might be able to tell me how this should be done.
For the benefit of anyone running into this thread - you can download the JAR file for javax.persistence here. Place this line in the folder src/android/libsof your custom plugin and then modify plugin.xmlwith the line
<lib-file src='src/android/libs/name-of-javax-persistence.jar'/>

Dependency issue creating SWRL Rule with SWRL API using gradle

I am trying to add a SWRL rule to my Ontology using SWRLAPI and OWLAPI. I am trying to use OWLAPI's version which is compatible with SWRLAPI. However, I still get errors when creating a rule. It seems to be a problem with the dependency management. I am using gradle as a dependency manager so this should have solved the issue.
The Exception is:
Error creating rule engine Drools. Exception: java.lang.NoClassDefFoundError. Message: org/drools/runtime/rule/AgendaFilter"
My build.gradle dependency file:
dependencies {
compile group: 'net.sourceforge.owlapi', name: 'owlapi-distribution', version: '4.1.3'
compile group: 'net.sourceforge.owlapi', name: 'org.semanticweb.hermit', version: '1.4.1.513'
compile 'edu.stanford.swrl:swrlapi:2.0.5'
compile 'edu.stanford.swrl:swrlapi-drools-engine:2.0.5'
}
The exception happens when executing createSWRLRuleEngine method:
public void addNewSWRLRule(SWRLRuleModel rule) throws SWRLBuiltInException, SWRLParseException {
SWRLRuleEngine swrlRuleEngine = SWRLAPIFactory.createSWRLRuleEngine(ontology);
swrlRuleEngine.infer();
swrlRuleEngine.createSWRLRule(rule.getName(), rule.getRule(), rule.getComment(), true);
}
Is there a dependency that must be added manually to solve this issue?
You're using HermiT 1.4.1.513. That's compatible with owlapi 5, not 4 (the patch number matches the owlapi version). Use HermiT 1.3.8.413.
The problem was that there were 2 maven dependencies from Drools Engine (edu.stanford.swrl:swrlapi-drools-engine:2.0.5) not resolved by gradle.
The missing dependencies were:
org.drools:knowledge-api:6.5.0.Final
org.drools:drools-osgi-integration:6.5.0.Final
I am not sure what is causing these not to be solved by gradle, but I managed to fix the issue in IntelliJ by converting the two missing dependencies to a Repository Library and searching for these in maven following these steps:
File > Project Structure > Libraries
Right button click on the missing library
Convert to Repository Library
Type the dependency name and search in maven repository
Replace

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

Cannot find symbol class "Generated" for Dagger 2

I just started doing dependency injection using Dagger 2. When I spun up my modules, components and tried to build my application, gradle threw the error
Error:(4, 24) error: cannot find symbol class Generated
I dug into it and found that the error is in one of the classes Dagger generates to do DI. The particular class that's missing was javax.annotation.Generated and the line throwing the error is the line that anntotates a Dagger generated class as #Generated("dagger.internal.codegen.ComponentProcessor")
This question helped in finding the solution which is to add the javax package as a dependency by adding the line compile 'org.glassfish:javax.annotation:10.0-b28' to my gradle build file. This led to a successful build.
My question is, why is that not added as a transitive dependency for Dagger or why hasn't anyone else faced this particular issue (I assume so, since I couldn't find any question here regarding this?
TL;DR use Dagger >= 2.1
Alex is right, but it's better to add JSR250 dependency instead of GlassFish
provided 'javax.annotation:jsr250-api:1.0'
or for the latest gradle plugin:
compileOnly 'javax.annotation:jsr250-api:1.0'
Read this for more info: https://github.com/google/dagger/issues/95
Basically, the solution is to do what you've already done which is include the glassfish javax annotation library.
This happens if your JAVA_HOME points to JAVA version 9 or 10. Switching JAVA_HOME to Java 8 fixes the problem and you will not need that extra dependency.
I downgraded my JVM to Java 8 and running gradle build was successful in my Android application using Dagger 2.
The right answer today is to use a version of dagger which is greater than 2.1 (because of the fix mentioned by #tomrozb is integrated in 2.1)

Categories

Resources