I am writing a project that makes use of LastModifiedFileComparator and I tried import this
import org.apache.commons.io.comparator.LastModifiedFileComparator;
but it shows the error.
cannot resolve symbol 'LastModifiedFileComparator'
I have put in these dependencies
// In top-level gradle file
repositories {
...
mavenCentral()
}
// In app gradle file
implementation 'org.apache.commons:commons-io:1.3.2'
implementation files('commons-io-2.6.jar')
I solved the error by downloading commons-io-1.4.jar with my browser and then copy and paste it in the android project lib
This class is not present in the version 1.3.2
Upgrade the version to 1.4 or greater
implementation group: 'commons-io', name: 'commons-io', version: '2.6'
Related
I am posting here to understand how does JHipster work with Gradle dependencies, in particular with regards to the fact that I am unable to copy some of them into a Gradle submodule I have created inside my JH project.
For example, the following doesn't work in a Gradle submodule
compile "junit:junit"
Error is
Could not resolve: junit:junit
However, the classic one copied from mvnrepository works great
compile group: 'junit', name: 'junit', version: '4.12'
Some additional information: I am creating a submodule that contains a set of classes related to testing, mainly a large load of custom Hamcrest matchers copied from another project from the Ant world. The original project had a lot of spaghetti code mess, so now I am refactoring into an isolated Gradle module. The testlib module shall depend on the testing frameworks and contain everything required for writing good tests. It can be compared to spring-test project you would use to write your own Spring-based tests.
At the moment, the gradle file looks like
plugins {
id "java"
}
configurations {
providedRuntime
implementation.exclude module: "spring-boot-starter-tomcat"
}
repositories {
mavenLocal()
mavenCentral()
jcenter()
}
group 'org.example' //different from com.acme of super-project
version '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
dependencies {
compile group: 'org.assertj', name: 'assertj-core', version: '3.13.2'
compile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.5.2'
compile group: 'org.hamcrest', name: 'hamcrest', version: '2.1'
compile group: 'org.mockito', name: 'mockito-core', version: '3.0.0'
compile group: 'org.springframework.boot', name: 'spring-boot', version: spring_boot_version
compile "junit:junit" //Fails
}
Question
So the question is in two parts:
why does the scope "orgId:name" syntax work in the JHipster-generated module but not in submodules? Is it part of standard Gradle syntax?
why is that not working in a sub-module? Does JHipster apply a custom plugin to apply the correct version number that is clearly missing? How I do the same in a sub-module that is supposed to contain only Java library code?
With regards to JHipster, a little of more investigation helped. According to this answer, there is a trick in Gradle called Bill Of Materials project, so...
TL;DR
Add the following to the sub-project
// import JHipster dependencies BOM
implementation platform("io.github.jhipster:jhipster-dependencies:${jhipster_dependencies_version}")
So that the whole block looks like
dependencies {
// import JHipster dependencies BOM
implementation platform("io.github.jhipster:jhipster-dependencies:${jhipster_dependencies_version}")
compile "org.assertj:assertj-core"
compile "org.junit.jupiter:junit-jupiter-api"
compile "org.hamcrest:hamcrest"
compile "org.mockito:mockito-core"
compile "org.springframework.boot:spring-boot"
compile "junit:junit"
}
Long answer
Maybe in the future when I will understand Gradle more. Or just edit this answer 😁 to contribute
The bom defines the versions (besides other things) of 3rd party dependencies to be used so you can omit the explicit version. If you do not use the bom you can also write compile "junit:junit:4.12" but keep in mind jhipster uses already junit5 for all tests by default.
Regarding the import of the bom you can do it like you proposed or try to apply that dependency to all gradle subprojects in your main gradle file.
I am compiling a java plugin that uses org.json. Before I included this the plugin was able to compiling and run correctly. I have seen similar problems on stackoverflow, but none of them address this problem using gradle.
In the top of my classes I have the following
import org.json.JSONArray;
import org.json.JSONObject;
My gradle build script contains the following:
repositories {
maven {
url "http://repo.dotcms.com/artifactory/libs-release"
}
mavenCentral()
flatDir {
dirs 'src/main/resources/localLibs'
}
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile fileTree(dir: 'src/main/resources/libs', include: '*.jar')
compile (group: 'com.dotcms', name: 'dotcms', version: '4.2.2'){
transitive = true
}
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.8.8'
compile group: 'org.json', name: 'json', version: '20170516'
compile group: 'org.simpleflatmapper', name: 'sfm-csv', version: '3.14.1'
/* Specifying an alternate configuration (see above 'configurations') keeps servlet-api.jar from being added to our own output Jar. */
providedCompile "javax.servlet:javax.servlet-api:3.1.0"
testCompile group: 'junit', name: 'junit', version: '4.12'
}
jar {
manifest {
name = 'Symplicity SOAP API Web Service'
symbolicName = 'Symplicity SOAP API Web Service'
instruction 'Bundle-Vendor', 'JustinKubicek'
instruction 'Bundle-Name', 'Symplicity SOAP API Web Service'
instruction 'Bundle-Description', 'This is a plugin to access the Symplicity SOAP API Web Service'
instruction 'Bundle-DocURL', 'https://bitbucket.org/justinkubicek/symplicity-soap-api-plugin'
instruction 'Bundle-Activator', 'com.symplicitysoapapi.soapapitool.osgi.Activator'
instruction 'DynamicImport-Package', '*'
instruction 'Import-Package', '*;version=0;'
}
}
The error I am getting is this here.
javax.servlet.ServletException: Unable to resolve Symplicity SOAP API Web Service
[197](R 197.0): missing requirement [Symplicity SOAP API Web Service [197](R 197.0)]
osgi.wiring.package; (&(osgi.wiring.package=org.json)(version>=0.0.0))
Unresolved requirements: [[Symplicity SOAP API Web Service [197](R 197.0)]
osgi.wiring.package; (&(osgi.wiring.package=org.json)(version>=0.0.0))]
Unable to start bundle
at com.dotmarketing.portlets.osgi.AJAX.OSGIAJAX.start(OSGIAJAX.java:122)
~[dotcms_4.2.2_999999.jar:?]
Unless you need a custom version of the JSON libraries, I would recommend changing your imports to use the repackaged classes that are included in dotCMS libraries. The classes there are repackaged to allow developers to include custom versions of this library if needed. Here is a list of the json classes available in the 4.2.2 release:
./dotserver/tomcat-8.0.18/webapps/ROOT/WEB-INF/lib/dot.json-ukv_2.jar:com/dotcms/repackage/org/json/XMLTokener.java
./dotserver/tomcat-8.0.18/webapps/ROOT/WEB-INF/lib/dot.json-ukv_2.jar:com/dotcms/repackage/org/json/XML.java
./dotserver/tomcat-8.0.18/webapps/ROOT/WEB-INF/lib/dot.json-ukv_2.jar:com/dotcms/repackage/org/json/Test.java
./dotserver/tomcat-8.0.18/webapps/ROOT/WEB-INF/lib/dot.json-ukv_2.jar:com/dotcms/repackage/org/json/JSONWriter.java
./dotserver/tomcat-8.0.18/webapps/ROOT/WEB-INF/lib/dot.json-ukv_2.jar:com/dotcms/repackage/org/json/JSONTokener.java
./dotserver/tomcat-8.0.18/webapps/ROOT/WEB-INF/lib/dot.json-ukv_2.jar:com/dotcms/repackage/org/json/JSONStringer.java
./dotserver/tomcat-8.0.18/webapps/ROOT/WEB-INF/lib/dot.json-ukv_2.jar:com/dotcms/repackage/org/json/JSONString.java
./dotserver/tomcat-8.0.18/webapps/ROOT/WEB-INF/lib/dot.json-ukv_2.jar:com/dotcms/repackage/org/json/JSONObject.java
./dotserver/tomcat-8.0.18/webapps/ROOT/WEB-INF/lib/dot.json-ukv_2.jar:com/dotcms/repackage/org/json/JSONML.java
./dotserver/tomcat-8.0.18/webapps/ROOT/WEB-INF/lib/dot.json-ukv_2.jar:com/dotcms/repackage/org/json/JSONException.java
./dotserver/tomcat-8.0.18/webapps/ROOT/WEB-INF/lib/dot.json-ukv_2.jar:com/dotcms/repackage/org/json/JSONArray.java
./dotserver/tomcat-8.0.18/webapps/ROOT/WEB-INF/lib/dot.json-ukv_2.jar:com/dotcms/repackage/org/json/HTTPTokener.java
./dotserver/tomcat-8.0.18/webapps/ROOT/WEB-INF/lib/dot.json-ukv_2.jar:com/dotcms/repackage/org/json/HTTP.java
./dotserver/tomcat-8.0.18/webapps/ROOT/WEB-INF/lib/dot.json-ukv_2.jar:com/dotcms/repackage/org/json/CookieList.java
./dotserver/tomcat-8.0.18/webapps/ROOT/WEB-INF/lib/dot.json-ukv_2.jar:com/dotcms/repackage/org/json/Cookie.java
./dotserver/tomcat-8.0.18/webapps/ROOT/WEB-INF/lib/dot.json-ukv_2.jar:com/dotcms/repackage/org/json/CDL.java
./dotserver/tomcat-8.0.18/webapps/ROOT/WEB-INF/lib/dot.json-ukv_2.jar:com/dotcms/repackage/org/json/
Of course to use these classes at runtime you need to make sure they are listed in your Exported Packages list: https://dotcms.com/docs/latest/osgi-plugins#ExportedPackages
I have a Gradle project with some third party dependencies.
My jar has been working fine until I added SQLServer dependency.
Here is a snapshot of build.gradle:
group 'MyApp'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'idea'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile 'com.amazonaws:aws-java-sdk:1.11.60'
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.6'
compile files('mylibraries/ojdbc7.jar')
compile files('mylibraries/postgresql-42.1.4.jar')
compile files('mylibraries/mssql-jdbc-6.2.1.jre8.jar')
}
jar {
from {
configurations.compile.collect {
it.isDirectory() ? it : zipTree(it)
}
}
manifest {
attributes 'Main-Class': 'MainLauncher'
}
}
Everything breaks down after compile files('mylibraries/mssql-jdbc-6.2.1.jre8.jar') has been added to dependencies. The error I get:
Error: Could not find or load main class MainLauncher
What could be a potential problem? Thank you!
Today i faced exactly same issue and i reached to this page to get the resolution
I was running jar with below dependency
group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: '6.2.2.jre8'
and i was facing exactly same issue,
Error: Could not find or load main class
later i changed dependency with older version and it run fine after this change
group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version:
'6.2.1.jre7'
I've had the same problem some time ago. I just imported the project and wanted to do a gradle clean build. I had exactly the same error.
I could solve this by just making sure I had at least one migration. It may sound silly but just try to create 1 migration for your database.
At least it solved my problem and I surely hope it solves yours too!
I'm creating a project which uses the Squash SQL Library for Kotlin. I've added the dependency to my build.gradle file. When running the update it just finishes without outputting any errors. But the library is not getting imported in my project and doesn't appear at all.
The dependencies shown in IntelliJ:
My build.gradle file:
//Kotlin Stuff, nothing changed here
repositories {
mavenCentral()
maven {
url "http://dl.bintray.com/kotlin/squash"
}
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
testCompile group: 'junit', name: 'junit', version: '4.12'
compile 'org.jetbrains.squash:squash:0.2.2'
}
//Kotlin Stuff
The dependency you've added is just the parent-pom which doesn't have any jar's in the repo. Here is the list of the squash projects (http://dl.bintray.com/kotlin/squash/org/jetbrains/squash/):
squash-core
squash-graph
squash-h2
squash-jdbc
squash-postgres
squash-sqlite
I guess you want to import the squash-core so change
compile 'org.jetbrains.squash:squash:0.2.2'
to
compile 'org.jetbrains.squash:squash-core:0.2.2'
tl;dr; adding adding dependencies to build.gradle downloads it fine but doesn't add it to the classpath/external libraries in idea.
Hi guys
Im new to developing webapps in java, and im trying to depend on a few jars on mvnrepository.com, the only time the dependencies are downloaded into the external libraries and added to the classpath is when i import the project as a gradle project, as in, each time i have a project up and running and i add a new dependency i would have to import the whole project into intellij again.
my build.gradle file looks like this:
group 'project_name'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'idea'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
// https://mvnrepository.com/artifact/com.google.inject/guice
compile group: 'com.google.inject', name: 'guice', version: '3.0'
// https://mvnrepository.com/artifact/org.apache.tomcat.embed/tomcat-embed-core
compile group: 'org.apache.tomcat.embed', name: 'tomcat-embed-core', version: '9.0.0.M9'
// https://mvnrepository.com/artifact/com.sun.jersey/jersey-core
compile group: 'com.sun.jersey', name: 'jersey-core', version: '1.19.1'
// https://mvnrepository.com/artifact/com.sun.jersey/jersey-json
compile group: 'com.sun.jersey', name: 'jersey-json', version: '1.19.1'
// https://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-client
compile group: 'org.glassfish.jersey.core', name: 'jersey-client', version: '2.23.2'
// https://mvnrepository.com/artifact/com.sun.jersey/jersey-servlet
compile group: 'com.sun.jersey', name: 'jersey-servlet', version: '1.19.1'
// https://mvnrepository.com/artifact/com.sun.jersey/jersey-server
compile group: 'com.sun.jersey', name: 'jersey-server', version: '1.19.1'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
task wrapper(type: Wrapper) {
gradleVersion = '2.5'
}
When i add a new dependency to the list, and run ./gradlew build, with or without the --refresh-dependencies option it does download the new dependencies but it doesn't add the downloaded files to the external libraries/classpath so i can't import them into the java code. I saw a question similar to this one, where they accepted answers like running:
./gradlew idea
In my case this doesn't help at all, it just adds some autogenerated files in the directory with no clear difference to behavior.
Then they accepted importing the project as a gradle project aswell, which i have done - which works, but adding new dependencies doesn't work.
FYI I am using the gradle 2.5 wrapper and IDEA community 16.2
Okay. I solved/figured it out, Apparently it didn't help to just run build,
inside of intellij i had to go to View --> Tool Windows --> Gradle, it then opens the gradle window, where i could click the refresh button, which downloads the dependencies.
Thanks to anyone who looked it over :)