IntelliJ can't run gradle project due to missing Class - java

I just gave IntelliJ a try, because Eclipse annoyed me again. I imported my gradle project(jetty, vaadin) and it went quite smoothly. But when I tried to run it I encountered the following error message during "make":
Error:gradle-resources-test:vaadinsharedwidgets: java.lang.NoClassDefFoundError: org/apache/tools/ant/util/ReaderInputStream
"vaadinsharedwidgets" is a module of the project. From what I understand from the error, IntelliJ doesn't find ant, but this is intended because I don't use ant. It also not part of the transitive dependencies. The same project runs in eclipse fine and also building it in gradle works without any problems.
Update: I just checked in Eclipse and somehow the ant.jar is on the classpath in Eclipse but I can't link it to any project. I wonder how it got there.
Update2: Missing version information:
IntelliJ: v14.0.1 CE (no plugins)
Gradle: 2.2 (used via wrapper)
Java 8 (1.8.0 b05)
Vaadin 7.3.4
build.gradle:
apply from: 'http://nexus/gradle/vaadin.gradle'
apply from: 'http://nexus/gradle/java8.gradle'
version = '1.1'
description = "Gemeinsame Vaadin-Widgets"
vaadin.widgetset 'net.xyz.vaadinsharedwidgets.VaadinsharedWidgetsWidgetset'
dependencies {
compile project(':ibhtheme')
compile 'com.vaadin:vaadin-server:' + vaadin.version
compile 'com.vaadin:vaadin-client:' + vaadin.version
}
jar{
// Include source in jar
from sourceSets.main.allJava
}
sourceSets.main.resources.srcDir 'src/main/webapp'
vaadin.gradle:
apply from: 'http://plugins.jasoft.fi/vaadin.plugin?version=0.9.2'
configurations {
def conf = 'vaadin-client'
def sources = project.sourceSets.main
def testSources = project.sourceSets.test
if (!project.configurations.hasProperty(conf)) {
project.configurations.create(conf)
sources.compileClasspath += project.configurations[conf]
testSources.compileClasspath += project.configurations[conf]
testSources.runtimeClasspath += project.configurations[conf]
project.configurations[conf].exclude group: 'org.eclipse.jetty'
}
}
vaadin {
version '7.3.4'
push true
}
java8.gradle:
apply plugin: 'java'
sourceCompatibility = 1.8
targetCompatibility = 1.8
group = 'net.xyz'
dependencies {
compile 'org.slf4j:slf4j-api:1.7.5'
compile 'com.google.guava:guava:16.0.1'
compile 'org.springframework:spring-context:4.0.3.RELEASE'
testCompile 'org.testng:testng:6.8.7'
testCompile 'org.mockito:mockito-all:1.9.5'
testCompile 'org.easytesting:fest-assert-core:2.0M10'
testCompile 'org.springframework:spring-test:4.0.3.RELEASE'
}
Adding ant as an additional dependency to the module doesn't work.

I encountered the same error in a Java project with multiple subprojects in IntelliJ 14.
Updating to 15.0.1, refreshing the Gradle projects via Views → Tool Windows → Gradle in IntelliJ and restarting fixed the issue.

Choose File → Invalidate Caches / Restart from the menu and select Invalidate and Restart. That fixed the issue for me.

After some tinkering and try-and-error I found that the following code in the vaadin.gradle was the culprit and removed it:
configurations {
def conf = 'vaadin-client'
def sources = project.sourceSets.main
def testSources = project.sourceSets.test
if (!project.configurations.hasProperty(conf)) {
project.configurations.create(conf)
sources.compileClasspath += project.configurations[conf]
testSources.compileClasspath += project.configurations[conf]
testSources.runtimeClasspath += project.configurations[conf]
project.configurations[conf].exclude group: 'org.eclipse.jetty'
}
}
It was part of an outdated hack to use jetty9 instead of jetty8, which was used by older versions of the vaadin-gradle plugin. The current version uses 9.2.2 which seems to be fine.

Related

What is the issue with my simple build.gradle setup?

I'm having an issue with setting up my build.gradle in a standalone java app - and a very similar configuration works in one of my other projects. What am I missing here? I think this has to be a simple fix, but it eludes me at the moment.
My simple build.gradle:
apply plugin: 'java'
sourceCompatibility = 1.9
targetCompatibility = 1.9
apply plugin: 'eclipse'
repositories {
mavenCentral()
}
dependencies {
// https://mvnrepository.com/artifact/org.apache.poi/poi
compile group: 'org.apache.poi', name: 'poi', version: '4.1.0'
// https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml
compile group: 'org.apache.poi', name: 'poi-ooxml', version: '4.1.0'
}
The error message eclipse gives me (from the gradle process) when I refresh the gradle project:
CONFIGURE SUCCESSFUL in 0s
Could not resolve: org.apache.poi:poi:4.1.0
Could not resolve: org.apache.poi:poi-ooxml:4.1.0
How can I resolve this? I've read the gradle docs, and appeared to be following the process. Gradle documentation links showing my error are appreciated as well. Thank you.
To resolve the dependencies try running from the command line. From there you can work to solve the IDE issue.
As mentioned in the comments on the original post - #PaulPearson discovered it worked on his machine, and when I ran the gradle refresh outside of Eclipse (with gradle build via command line) it worked fine.
It must be an eclipse IDE specific issue - not an issue with the build.gradle. My acute issue is resolved. Thanks all.

Sudden loss of dependencies in Eclipse Gradle project

I'm working with a Gradle project in Eclipse Oxygen with Java 8 and Gradle wrapper 4.6.
When i tried to add a new dependency compile 'com.googlecode.json-simple:json-simple:1.1.1' and refresh the project, all the "Project and External Dependencies" folder disappeared without a trace, which stops my project running from Eclipse (it can run through Gradle Run task though).
Removing the newly added dependency does not save me. Neither gradlew cleanEclipse & gradlew eclipse nor refreshing the project countless times.
I also attempted to clear the cache and forced project to rebuild when reimport, but no "Project and External Dependencies" shows up.
What should i do to bring back the old dependencies?
Here is my build.gradle
// Apply the java plugin to add support for Java
apply plugin: 'java'
// Apply the plugin to be runnable
apply plugin: 'application'
// Apply the eclipse plugin to import project on other machines
apply plugin: 'eclipse'
// JUnit 5
apply plugin: 'org.junit.platform.gradle.plugin'
// Define the entry point
mainClassName = 'meshIneBits.MeshIneBitsMain'
applicationName = 'MeshIneBits'
// In this section you declare where to find the dependencies of your project
repositories {
// Use 'jcenter' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
sourceCompatibility = 1.8
// In this section you declare the dependencies for your production and test code
dependencies {
compile 'org.processing:core:3.3.5'
compile 'org.jogamp.jogl:jogl-all:2.3.2'
compile 'org.jogamp.gluegen:gluegen-rt:2.3.2'
runtime "org.jogamp.gluegen:gluegen-rt:2.3.2:natives-linux-amd64"
runtime "org.jogamp.gluegen:gluegen-rt:2.3.2:natives-linux-armv6"
runtime "org.jogamp.gluegen:gluegen-rt:2.3.2:natives-linux-armv6hf"
runtime "org.jogamp.gluegen:gluegen-rt:2.3.2:natives-linux-i586"
runtime "org.jogamp.gluegen:gluegen-rt:2.3.2:natives-macosx-universal"
runtime "org.jogamp.gluegen:gluegen-rt:2.3.2:natives-windows-amd64"
runtime "org.jogamp.gluegen:gluegen-rt:2.3.2:natives-windows-i586"
runtime "org.jogamp.jogl:jogl-all:2.3.2:natives-linux-amd64"
runtime "org.jogamp.jogl:jogl-all:2.3.2:natives-linux-armv6"
runtime "org.jogamp.jogl:jogl-all:2.3.2:natives-linux-armv6hf"
runtime "org.jogamp.jogl:jogl-all:2.3.2:natives-linux-i586"
runtime "org.jogamp.jogl:jogl-all:2.3.2:natives-macosx-universal"
runtime "org.jogamp.jogl:jogl-all:2.3.2:natives-solaris-i586"
runtime "org.jogamp.jogl:jogl-all:2.3.2:natives-windows-amd64"
runtime "org.jogamp.jogl:jogl-all:2.3.2:natives-windows-i586"
testCompile('org.junit.jupiter:junit-jupiter-api:5.1.0',
'org.junit.jupiter:junit-jupiter-params:5.1.0')
testRuntime('org.junit.jupiter:junit-jupiter-engine:5.1.0',
'org.junit.platform:junit-platform-launcher:1.1.0')
}
eclipse {
project.natures 'org.eclipse.buildship.core.gradleprojectnature'
classpath {
file {
defaultOutputDir = file('bin/main')
whenMerged {
//change output folder for tests
def testsrc = entries.find { it.path == 'src/test/java' }
testsrc.output = "bin/test"
def testres = entries.find { it.path == 'src/test/resources' }
testres.output = "bin/test"
// Remove local ref for libs
entries.removeAll{ it.kind == "lib" }
}
containers 'org.eclipse.jdt.junit.JUNIT_CONTAINER/5', 'org.eclipse.buildship.core.gradleclasspathcontainer' }
}
}
buildscript {
repositories { mavenCentral() }
dependencies { classpath 'org.junit.platform:junit-platform-gradle-plugin:1.1.0' }
}
jar {
baseName = applicationName
version = '0.2.0'
manifest { attributes 'Main-Class' : mainClassName }
}
Edit:
After switching to IntelliJ, the problem is solved (i used the same folder of project). So i think this is a problem in Eclipse.
I also had this problem where the "Project and External Dependencies" folder disappeared. It instead showed as 'org.eclipse.buildship.core.gradleclasspathcontainer'.
If you do not see that line, then it needs to be added to the .classpath file.
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer" />
The fix that worked for me was closing Eclipse, and running
gradlew cleanEclipse eclipse
then opening Eclipse and adding the Gradle nature to the project.
I also encountered this problem when I refactor the project name.
Following steps solve my problem:
add eclipse plugin to build.gradle
right click build.gradle, choose gradle then select refresh gradle project
only refresh gradle project didn't help me.

Add parameter to a Gradle plugin

I'm new to Gradle and I'm working on a Liferay project. I'm trying to use the Liferay javadoc gradle plugin without success. I'm working on the Liferay IDE (Eclipse) and I already have the javadoc task available to execute. The problem is, after the excution (which completes successfully) I can't find the created docs.
I read the documentation which says there is destinationDir property but I'm unable to set it using Gradle.
I tried following this SO question in order to create a custom Gradle task but without success.
How can I set the destinationDir in order to get the generated docs?
Edit:
The (automatic generated) settings.gradle is:
buildscript {
dependencies {
classpath group: "com.liferay", name: "com.liferay.gradle.plugins.workspace", version: "1.5.0"
classpath group: "net.saliman", name: "gradle-properties-plugin", version: "1.4.6"
}
repositories {
maven {
url "https://cdn.lfrs.sl/repository.liferay.com/nexus/content/groups/public"
}
}
}
apply plugin: "net.saliman.properties"
apply plugin: "com.liferay.workspace"
I'm pretty sure that com.liferay.gradle.plugins.workspace includes the javadoc plugin. Furthermore, Liferay also automatically creates an empty build.gradle where I put:
apply plugin: 'java'
task api(type: Javadoc) {
source = sourceSets.main.allJava
destinationDir = new File(buildDir, "/api")
}
Launching the api Gradle task the javadoc plugin is not executed

How to setup a Gradle build for a JSF2 application to be hosted by JBoss AS 7.1?

At this moment I have a build.gradle file that successfuly compiles and tests (using JUnit4) a very very simple java project.
My next step is to add JSF2 support (in order to have a web JSF2 application) to this build. The idea is to host the application in my local JBoss 7.1 container. Now things became a little fuzzy to me.
What I did was to add JSF2 support to my buid by adding some dependencies, so the dependencies block is like this now:
dependencies {
compile 'org.jboss.weld.se:weld-se-core:'+weldVersion
compile 'br.gov.frameworkdemoiselle:demoiselle-core:'+demoiselleVersion
compile 'br.gov.frameworkdemoiselle:demoiselle-jsf:'+demoiselleVersion
runtime 'javax.servlet:javax.servlet-api:3.1.0'
runtime 'javax.enterprise:cdi-api:1.0-SP1'
runtime 'org.jboss.weld.servlet:weld-servlet:'+weldVersion
runtime 'com.sun.faces:jsf-api:2.2.8-02'
runtime 'org.slf4j:slf4j-log4j12:1.7.7'
testCompile 'junit:junit:4.11'
testCompile 'org.jboss.arquillian.junit:arquillian-junit-container:'+arquillianVersion
testCompile 'br.gov.frameworkdemoiselle.component:demoiselle-junit:2.3.1'
}
First strange thing that I noticed is that after refreshing the project with Gradle (by using Gradle > Refresh All menu), JBoss is unable to see it. I noticed that (it seems) Gradle disabled the use of facets in the project. If I manually activate facets and set the runtime to JBoss 7.1, then I'll be able to add it to JBoss (but I would prefer not to have to do it manually anymore).
After adding it to JBoss I can run the server, and the log says the module corresponding to my web application was correctly loaded by JBoss, however when I type it's url in a browser, the server responds with HTTP status 404.
In src/main/webapp I have the simple index.html file (shown below), so what I expected was just to see it's content in the browser, but that does not happen.
<html>
<body>
<h1>Hello world!</h1>
</body>
</html>
What am I missing?
After some study I finally understood that things were much simpler. That I was missing to understand is that I was using the wrong Gradle plug-in. I had to replace eclipse plug-in by eclipse-wtp and then specify which facets and runtime I wanted to use in my application.
The final build.gradle file is below:
apply plugin: 'java'
apply plugin: 'eclipse-wtp' // The correct plug-in!
apply plugin: 'application'
apply plugin: 'war'
sourceCompatibility = 1.7
targetCompatibility = 1.7
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
def hibernateVersion = "4.3.7.Final"
def weldVersion = "1.1.27.Final"//"2.2.7.Final" Demoiselle 2.4.1 não é compatível com Weld 2
def demoiselleVersion = "2.4.1"
def arquillianVersion = "1.1.5.Final"
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
runtime 'javax.servlet:javax.servlet-api:3.1.0'
runtime 'javax.enterprise:cdi-api:1.0-SP1'
runtime 'org.jboss:jandex:1.2.2.Final'
}
eclipse {
wtp {
facet {
facet name: "java", version: "1.7" // Java version
facet name: "jst.web", version: "3.0" // Dynamic Web Application
facet name: "jst.jsf", version: "2.2" // Java Server Faces
facet name: "wst.jsdt.web", version: "1.0" // JavaScript
}
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.2.1'
}
I hope this may help some other people!

Gradle with IntelliJ not loading PostgreSQL JDBC as a dependency

I am trying to setup IntelliJ alongwith Gradle and JOOQ for my next project. As of now, this is how my Gradle file looks like:
apply plugin: 'java'
apply plugin: 'jooq'
sourceCompatibility = 1.5
version = '1.0'
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
}
dependencies {
compile 'org.jooq:jooq:3.1.0'
compile 'com.google.guava:guava:14.0'
compile 'postgresql:postgresql:9.1-901-1.jdbc4'
}
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'postgresql:postgresql:9.1-901-1.jdbc4'
classpath 'com.github.ben-manes:gradle-jooq-plugin:0.5'
}
}
jooq {
... snip ...
}
And this is how my external dependencies (in IntelliJ) show up:
.
Somehow, Gradle is downloading and IntelliJ is recognizing the jooq and guava as part of my dependencies, but postgresql does not show up. So, while doing this works (using Guava, a dependency loaded from Gradle):
List<String> stringList = Lists.newArrayList();
This fails with a ClassNotFoundException:
Class.forName("org.postgresql.Driver").newInstance();
While doing a ./gradlew build, I have seen gradle output the fact that it did download thr postgresql-9.1-901 jar from Maven Central, but I don't know where it keeps it. Any help is greatly appreciated.
Apparently, I really need to RTFM. I hadn't refreshed the dependencies from the Gradle tool window in IntelliJ after making changes to the Gradle script. Got it from here: https://www.jetbrains.com/idea/webhelp/synchronizing-changes-in-gradle-project-and-intellij-idea-project.html

Categories

Resources