Dependency issue creating SWRL Rule with SWRL API using gradle - java

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

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

How to add com.fasterxml.jackson.core.exc.InputCoercionException as a dependency in gradle?

I am getting java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/PropertyNamingStrategies which is used in another project. I have included jackson jar in current gradle project as well. But while starting the project I am getting the above mentioned error. Seems like we need to add com.fasterxml.jackson.core.exc.InputCoercionException as an dependency but I am not able to understand where to add this as a dependency ? Can someone please help ?
java.lang.NoClassDefFoundError Either means - missing dependency with class com/fasterxml/jackson/databind/PropertyNamingStrategies or class was removed meaning jackson libs versions used in your project dependencies won't work together.
How to start solving problems like those.
1, Via IDE try to find missing class if is present. If is not present then try to find jar with missing class on internet and add as dependency. In case your IDE show class is present then problem may be with import scope. Scope management differ per used technology so provide detail which one you use or paste dependencies from build.kts . Make sure you use implementation in case you import this class in project and not runtimeOnly.
2, You found class then try to print project dependency tree command differ per used technology. For gradle ./gradlew dependencies or for submodule ./gradlew submoduleName:dependencies and look at versions of jackson in your project.
3, Check jackson lib with version listed via dependency tree contains missing class.
How to avoid problem like those with spring boot.
I would recoment to use BOM provided by spring boot project, versions in there should work together.
For gradle with kotlin DSL we import it like this
import org.springframework.boot.gradle.plugin.SpringBootPlugin
plugins {
id("org.springframework.boot") version "2.6.2"
}
dependencies {
val springBootPlatform = platform(SpringBootPlugin.BOM_COORDINATES)
annotationProcessor(springBootPlatform)
implementation(springBootPlatform)
//this version has to be searched for spring boot version
implementation(platform("org.springframework.cloud:spring-cloud-dependencies:2021.0.0"))
//put desired jackson dependencies
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
}

Gradle dependency NoSuchMethodError 'AnnotationAttributes.getAliasedStringArray'

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.

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

Error compiling gradle project with dependency on version 0.3.150227 google-cloud-dataflow-java-sdk-all

I'm working on a Java app that is using Google Cloud Data flow and I'm getting errors when trying to compile using gradle.
Dependencies section in build.gradle is:
dependencies {
compile 'commons-codec:commons-codec:1.9'
compile 'com.google.cloud.dataflow:google-cloud-dataflow-java-sdk-all:0.3.150227'
compile 'com.google.inject.extensions:guice-multibindings:3.0'
compile 'com.google.inject:guice:3.0'
}
The error I'm getting is:
Could not resolve
com.google.cloud.dataflow:google-cloud-dataflow-java-proto-library-all:0.3.150206.
Required by:
:telstra-targetingserver-cdf-cptmappings:0.0.1 > com.google.cloud.dataflow:google-cloud-dataflow-java-sdk-all:0.3.150227
Could not parse POM https://repo1.maven.org/maven2/com/google/cloud/dataflow/google-cloud-dataflow-java-proto-library-all/0.3.150206/google-cloud-dataflow-java-proto-library-all-0.3.150206.pom
Could not find com.google.cloud.dataflow:google-cloud-dataflow-java-sdk-parent:LATEST.
Searched in the following locations:
file:/Users/pablocaif/.m2/repository/com/google/cloud/dataflow/google-cloud-dataflow-java-sdk-parent/LATEST/google-cloud-dataflow-java-sdk-parent-LATEST.pom
file:/Users/pablocaif/.m2/repository/com/google/cloud/dataflow/google-cloud-dataflow-java-sdk-parent/LATEST/google-cloud-dataflow-java-sdk-parent-LATEST.jar
https://repo1.maven.org/maven2/com/google/cloud/dataflow/google-cloud-dataflow-java-sdk-parent/LATEST/google-cloud-dataflow-java-sdk-parent-LATEST.pom
https://repo1.maven.org/maven2/com/google/cloud/dataflow/google-cloud-dataflow-java-sdk-parent/LATEST/google-cloud-dataflow-java-sdk-parent-LATEST.jar
LATEST appears to be missing in https://repo1.maven.org/maven2/com/google/cloud/dataflow/google-cloud-dataflow-java-sdk-parent/
The content at this time is:
This is a known issue which will be resolved with the next Maven push of Cloud Dataflow which is planned for next Monday (3/23).

Categories

Resources