gradle project's build fails - java

I have a java EE project. I am using gradle as a build tool. My build.gradle file looks as follows:
apply plugin:'war'
apply plugin:'eclipse'
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "com.eriwen:gradle-js-plugin:1.12.1"
}
}
apply plugin: "com.eriwen.gradle.js"
minifyJs {
source = file("src/main/webapp/js/App.js")
dest = file("build/all-min.js")
closure {
warningLevel = 'QUIET'
}
}
war.doFirst {
tasks.minifyJs.execute()
}
war.webInf {
from "build/all-min.js"
into "/js/"
}
dependencies{
compile 'org.springframework:spring-context:4.1.4.RELEASE'
compile 'org.springframework:spring-core:4.1.4.RELEASE'
compile 'org.springframework:spring-web:4.1.4.RELEASE'
compile 'org.springframework:spring-webmvc:4.1.4.RELEASE'
compile 'org.springframework:spring-jdbc:4.1.4.RELEASE'
compile 'org.springframework:spring-tx:4.1.4.RELEASE'
compile 'org.google.code.gson:gson:2.3.1+'
compile 'log4j:log4j:1.2.17+'
compile 'org.slf4j:jcl-over-slf4j:1.5.8+'
compile 'org.slf4j:slf4j-api:1.5.8+'
compile 'org.slf4j:slf4j-log4j12:1.5.8+'
compile 'org.apache.commons:commons-dbcp2:2.0.1+'
compile 'org.mybatis:mybatis-spring:1.2.2+'
compile 'org.mybatis:mybatis:3.2.8+'
compile 'com.oracle:ojdbc14:10.2.0.4.0+'
compile 'commons-fileupload:commons-fileupload:1.2.1+'
compile 'commons-io:commons-io:2.4+'
compile 'junit:junit:4.11'
compile 'javax.servlet:servlet-api:2.5'
}
However when I try to execute gradle build I get the following error
couldnot resolve all dependencies required for configuration for all the dependencies that I have mentioned in my build.gradle file. I think I have correctly mentioned the repositories . I cant figure out why my build is failing. Any suggestion would be appreciated.

You need to add a repositories {...} configuration block to your build script. The one declared inside the buildscript {...} block is only used for resolving dependencies of the build script itself (in this case, the javascript plugin), but it is not used for resolving project dependencies.

Related

Gradle method not found:'compile' possible causes : The Project

dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:design:24.1.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
i'm trying to add compile method to build.gradle but i get this problem
i have android studio 3.5.2
and 5.4.1 gradle
You can replace compile with implementation:
implementation 'com.android.support:appcompat-v7:24.1.1'
implementation 'com.android.support:design:24.1.1'
But you are putting your dependencies in your build.gradle module Project. Place them in build.gradle module app.

build.gradle: compile group vs compile, buildscript, classpath

What is the difference between "compile group" and "compile"? Just another way to define a dependency?
Ex:
compile group: 'org.slf4j', name: 'slf4j-jcl', version: '1.7.21'
And i think this also will work:
compile("org.slf4j:slf4j-jcl:1.7.21")
Why do i have the declare mavenCentral() again and another dependencies block inside the buildscript block?
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.0.RELEASE")
}
}
From my point of view, when you compile something it will be in your classPath?
compile specifies an external dependency for the project you are building. compile requires group, name, and version. These can either be broken out or specified using the short form "group:name:version". see Gradle Dependency Management Basics
The buildscript block declares the dependencies of your gradle build itself while the normal dependencies block declares the dependencies of the project you are going to build

gradle circular dependency with external project

I have a fairly simple setup, that does not work and I cannot work out why:
the folder structure is as follows:
/dependency
/build.gradle
/settings.gradle
/src/main/...
/Mainproject
/build.gradle
/settings.gradle
/Subproject_1
/build.gradle
/src/main...
/Subproject_2
/build.gradle
/src/main...
I want the Subproject to depend on "dependency" locally for quick testing.
so I stuck to the manual and did:
/Mainproject/settings.gradle:
include "Subproject_1", "Subproject_2", "dependency"
project(":dependency").projectDir = file('../dependency')
/Mainproject/build.gradle:
allprojects {
apply plugin: 'java'
dependencies {
compile project(path: ':dependency')
}
}
dependencies {
compile project(':Subproject_1')
compile project(':Subproject_2')
}
/dependency/build.gradle:
version '1.0'
apply plugin: 'java'
repositories {
maven {
url "http://...."
}
}
dependencies {
compile group: 'commons-lang', name: 'commons-lang', version: '2.6'
compile group: 'javax', name: 'javaee-api', version: '7.0'
}
jar {
manifest {
attributes 'Implementation-Title': 'Archive delegation dispatcher classes',
'Implementation-Version': project.version
}
}
The build.gradle files of Subproject_1 and _2 are empty.
The settings.gradle file of dependency is empty.
When i gradle build MainProject i get:
Circular dependency between the following tasks:
:dependency:classes
\--- :dependency:compileJava
\--- :dependency:jar
\--- :dependency:classes (*)
(*) - details omitted (listed previously)
And I cannot get my head around why that would be.
Any hints?
When you include "dependency" in your Mainproject's settings.gradle file, you are making the "dependency" project a subproject of "Mainproject".
Then this block in your Mainproject's build.gradle file defines "dependency" as a compile dependency of all subprojects.
allProjects {
dependencies {
compile project(path: ':dependency')
}
}
Since the "dependency" project is also a subproject, you have a circular dependency defined where the "dependency" project depends on itself.
Instead, try creating a settings.gradle file for each of the subprojects with the following:
include "dependency"
project(":dependency").projectDir = file('../dependency')
Then modify your settings.gradle file for the Mainproject to look like this:
include "Subproject_1", "Subproject_2"
You've stated that allProjects have a dependency on the project dependency as seen here:
allprojects {
apply plugin: 'java'
dependencies {
compile project(path: ':dependency')
}
}
You need this to only apply to your projects that aren't dependency. You can do that by excluding it when applying dependencies, like this
subprojects { project ->
if (project.name != "dependency") {
apply plugin: 'java'
dependencies {
compile project(path: ':dependency')
}
}
}
Because dependencies itself.
Move it must be OK.
Turning off Instant run worked for me, could work for someone else too. I had some changes related to gradle and my application appeared not to work after it.
build.gradle (:shared)
This is because you are trying to include a module inside of yourself.
From:
dependencies {
implementation project(':shared')
...
}
To:
dependencies {
...
}
GL
Source

How do you include the JMonkey test data jar on a Gradle project?

I've followed the instructions to creating a Gradle project using JMonkey but I have been unable to get any of the assets to load as stated in the tutorial:
http://wiki.jmonkeyengine.org/doku.php/jme3:beginner:hello_asset
My build.gradle looks like this:
apply plugin: 'java'
apply plugin: 'eclipse'
sourceCompatibility = 1.8
version = '1.0'
jar {
manifest {
attributes 'Implementation-Title': 'Gradle Quickstart', 'Implementation-Version': version
}
}
repositories {
mavenCentral()
maven {
url 'http://updates.jmonkeyengine.org/maven'
}
}
dependencies {
compile 'com.jme3:jme3-core:3.0.+'
compile 'com.jme3:jme3-effects:3.0.+'
compile 'com.jme3:jme3-networking:3.0.+'
compile 'com.jme3:jme3-plugins:3.0.+'
compile 'com.jme3:jme3-jogg:3.0.+'
compile 'com.jme3:jme3-terrain:3.0.+'
compile 'com.jme3:jme3-blender:3.0.+'
compile 'com.jme3:jme3-jbullet:3.0.+'
compile 'com.jme3:jme3-niftygui:3.0.+'
compile 'com.jme3:jme3-desktop:3.0.+'
compile 'com.jme3:jme3-lwjgl:3.0.+'
}
The sample was created from the wiki: http://wiki.jmonkeyengine.org/doku.php/jme3:maven
However the wiki makes no references to assets or how to build them.
After looking through the internet I found that the jar that I'm looking for is the jME3-testdata.jar. According to this conversation: http://hub.jmonkeyengine.org/t/official-maven-repo-for-jme3-0-stable-available-please-test/30571
It was a deliberate decision not to include the test data jar. Because of this, I went ahead and manually downloaded the missing jar and added it to my classpath.

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