Project has Gradle 5 (gradle-5.0-milestone-1), Java 11 (OpenJDK11) and latest IntelliJ Professional.
With sourceCompatibility = 10 in gradle.properties it builds/runs tests, but with sourceCompatibility = 11 it shows
module not found: java.xml.ws.annotation
Note that If I run test task from Gradle it runs everything successfully but it only fails when running directly from IntelliJ (pointing on method, right click and run).
Does anyone have any idea what is going wrong here?
For those who run into similar problem. Removing .idea folder and reimporting whole project helped.
Add to gradle
compile group: 'javax.xml.ws', name: 'jaxws-api', version: '2.3.1'
compile 'com.sun.xml.bind:jaxb-osgi:2.4.0-b180830.0438'
compile group: 'com.sun.xml.ws', name: 'jaxws-ri', version: '2.3.1', ext: 'pom'
compile group: 'com.sun.xml.bind', name: 'jaxb-impl', version: '2.4.0-b180830.0438'
Could you please verify that you don't have '--add-modules', 'java.xml.ws.annotation' in your build.gradle, because this module was removed in JDK11, but is still needed for JDK 10.
https://jaxenter.com/jdk-11-java-ee-modules-140674.html
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 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!
when i add slf4j-api-1.6.4.jar and slf4j-nop-1.6.4.jar in my libs folder it works fine but if i replaced them with gradle dependency then while executing the jar it gives me below error.
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
these are gradle dependencies for my project for above libraries.
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.6.4'
compile group: 'org.slf4j', name: 'slf4j-nop', version: '1.6.4'
Make sure you've run Gradle Build, it may not have pulled your dependencies.
Make sure that you include these dependencies in the jar file (like this).
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 :)
I am getting the following exception while running run-war on IntelliJ IDEA.
| Uglifying File 44 of 464 - application.
| Error Error executing script RunWar: com.google.common.collect.Maps.immutableEnumMap(Ljava/util/Map;)Lcom/google/common/collect/ImmutableMap; (NOTE: Stack trace has been filtered.
Use --verbose to see entire trace.)
java.lang.NoSuchMethodError: com.google.common.collect.Maps.immutableEnumMap(Ljava/util/Map;)Lcom/google/common/collect/ImmutableMap;
at com.google.javascript.jscomp.parsing.parser.Keywords.<clinit>(Keywords.java:94)
at com.google.javascript.jscomp.parsing.parser.Scanner.scanIdentifierOrKeyword(Scanner.java:681)
at com.google.javascript.jscomp.parsing.parser.Scanner.scanToken(Scanner.java:569)
at com.google.javascript.jscomp.parsing.parser.Scanner.peekToken(Scanner.java:228)
at com.google.javascript.jscomp.parsing.parser.Parser.peekToken(Parser.java:2737)
at com.google.javascript.jscomp.parsing.parser.Parser.peekToken(Parser.java:2730)
at com.google.javascript.jscomp.parsing.parser.Parser.getTreeStartLocation(Parser.java:2649)
at com.google.javascript.jscomp.parsing.parser.Parser.parseProgram(Parser.java:147)
at com.google.javascript.jscomp.parsing.ParserRunner.parse(ParserRunner.java:102)
at com.google.javascript.jscomp.JsAst.parse(JsAst.java:84)
at com.google.javascript.jscomp.JsAst.getAstRoot(JsAst.java:50)
at com.google.javascript.jscomp.CompilerInput.getAstRoot(CompilerInput.java:118)
at com.google.javascript.jscomp.Compiler.hoistExterns(Compiler.java:1467)
at com.google.javascript.jscomp.Compiler.parseInputs(Compiler.java:1369)
at com.google.javascript.jscomp.Compiler.parse(Compiler.java:788)
at com.google.javascript.jscomp.Compiler.compileInternal(Compiler.java:743)
at com.google.javascript.jscomp.Compiler.access$000(Compiler.java:93)
at com.google.javascript.jscomp.Compiler$3.call(Compiler.java:655)
at com.google.javascript.jscomp.Compiler$3.call(Compiler.java:652)
at com.google.javascript.jscomp.Compiler$4.call(Compiler.java:699)
If I run the same app using run-app it works.
This is BuildConfig.groovy:
build ":tomcat:7.0.55"
compile ':cache:1.1.8'
compile ":asset-pipeline:2.1.1"
compile ":easygrid:1.6.9"
compile ":twitter-bootstrap:3.3.2.1"
compile ':spring-security-core:2.0-RC4'
compile ":jquery-validation-ui:1.4.9"
compile ":birt-report:4.3.0.3"
runtime ":hibernate:3.6.10.18"
runtime ":database-migration:1.4.0"
runtime ":jquery:1.11.1"
Any idea what it might be? or how to solve it?
Adding a build-scoped dependency on Guava fixed this issue for me in a Grails 2.5.2 app
dependencies {
// other dependencies go here
build 'com.google.guava:guava:18.0'
}
https://code.google.com/p/guava-libraries/wiki/UseGuavaInYourBuild
Make sure you have two things set in your BuildConfig:
repositories {
mavenCentral()
}
dependencies {
compile group: 'com.google.guava', name: 'guava', version: '12.0'
}
Just make sure you're using the correct version that you need. Then do a Grails Refresh Dependencies.
I had the same problem with Grails 2.5.0 and I fixed it by bumping the guava version to the latest available.
In my grails-app/conf/BuildConfig.groovy, I now have:
dependencies {
compile group: 'com.google.guava', name: 'guava', version: '18.0'
}
And that resolved the issue.
I had the same error and fix it using the latest asset plugin:
(compile "org.grails.plugins:asset-pipeline:2.11.0")