Gradle Eclipse task not resolving dependencies from MavenLocal - java

I have my gradle build script set to resolve a TeraData dependency that I have installed to my local maven repository (this dependency is not available on Maven Central). The problem is that the eclipse plugin fails to resolve these dependencies when generating the .classpath file when I execute gradle eclipse.
This is the generated .classpath, with the problematic classpath entries:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="output" path="bin"/>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry sourcepath="D:/Users/Me/.gradle/this/one/is/good.jar" kind="lib" path="D:/Users/Me/.gradle/caches/modules-2/files-2.1/this/one/is/good.jar"/>
<classpathentry kind="lib" path="D:/dev/workspaces/myworkspace/myproject/unresolved dependency - com.teradata.jdbc terajdbc4 15.10.00.09"/>
<classpathentry kind="lib" path="D:/dev/workspaces/myworkspace/myproject/unresolved dependency - com.teradata.jdbc tdgssconfig 15.10.00.09"/>
</classpath>
This is my gradle.build script, largely copied directly from artifactory's recommended settings:
buildscript {
repositories {
maven {
url 'https://dev.mycompany.com/artifactory/plugins-release'
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
mavenLocal()
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.0.3"
}
}
allprojects {
apply plugin: "com.jfrog.artifactory"
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'
}
artifactory {
contextUrl = "${artifactory_contextUrl}"
publish {
repository {
repoKey = 'libs-release-local'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
resolve {
repository {
repoKey = 'libs-release'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
}
dependencies {
/** Note: teradata must be manually installed to local maven repo. **/
compile 'com.teradata.jdbc:terajdbc4:15.10.00.09'
compile 'com.teradata.jdbc:tdgssconfig:15.10.00.09'
}
What is causing the TeraData dependencies to not be resolved? How can I fix it?

You're resolving buildscript dependencies from mavenLocal, but not your project dependencies. Try adding this after the buildscript block:
repositories {
mavenLocal()
}

Related

Gradle multimodule project - how to create library with individual module as dependency jar

Below is my multimodule project setup.
Root project 'gradle-lib'
+--- Project ':environment-config1'
+--- Project ':environment-config2'
+--- Project ':environment-api'
\--- Project ':environment-lib'
gradle-lib/build.gradle
plugins {
id "org.springframework.boot" version "2.6.7" apply false
id "io.spring.dependency-management" version "1.0.11.RELEASE" apply false
}
subprojects { final Project subproject ->
apply plugin: 'org.springframework.boot'
apply plugin: 'java'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'jacoco'
apply plugin: 'java-library'
apply plugin: 'maven-publish'
version = rootProject.version
group = rootProject.group
repositories {
mavenLocal()
mavenCentral()
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
// No spring boot application
bootJar {
enabled = false
}
jar {
enabled = true
// Remove `plain` postfix from jar file name
archiveClassifier.set("")
}
sourceCompatibility = '1.8'
// Add dependencies that common to all projects
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
environment-config1/build.gradle
dependencies {
implementation project(":environment-api")
}
environment-config2/build.gradle
dependencies {
implementation project(":environment-api")
}
environment-api/build.gradle
// Boiler plate code with some jar dependencies
dependencies {
}
environment-lib/build.gradle
dependencies {
implementation project(":environment-api")
implementation project(":environment-config1")
implementation project(":environment-config2")
}
Whenever I try to build this project with gradlew clean build, these is compileJava task failed at 'environment-lib' which actually uses certain class files from environment-config1 & environment-api projects.
I could suppress the same as below, but what configuration: 'default' will do?
implementation project(":environment-api", configuration: 'default')
implementation project(":environment-config1", configuration: 'default')
implementation project(":environment-config2", configuration: 'default')
How can I create a single jar with other module as individual jar like below. Is it possible or recommended way?
gradle-lib-1.0.0.jar ---> + META-INF
\- MANIFEST.MF
+ //source files of environment-lib project
+ lib
\- environment-api-1.0.0.jar
\- environment-config1-1.0.0.jar
\- environment-config2-1.0.0.jar

Gradle subproject not recognizing 3rd party dependencies from root build.gradle

I have a project like this:
module1
src/
build.gradle
module2
src/
build.gradle
build.gradle
settings.gradle
In the root build.gralde I am defining 3rd party dependencies needed by all submodules. However, in intellij the submodules don't seem to recognize the dependencies and won't compile. I've seen this work in the past and can't figure out what I'm doing wrong
Root build.gradle
plugins {
id 'java'
}
group 'com.XXX'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
allprojects {
repositories {
mavenLocal()
mavenCentral()
jcenter()
}
}
dependencies {
...
}
settings.gradle
rootProject.name = 'XXX'
include 'module1'
include 'module2'
module1 build.gradle
plugins {
id 'java'
}
group 'com.XXX'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
I realized I just needed to put the dependencies in the root build.gradle within a "subprojects" block and add the java plugin as well.
subprojects {
apply plugin: 'java'
dependencies {
...
}
}

Eclipse Junit: java.lang.ClassNotFoundException

I have the following problem:
I have a java project that uses gradle. The project structure is:
src
- main
-- java
-- resources
- test
-- java
-- resources
I have the following test class:
package it.main.tests;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class MainTest {
#Test
public void mainTests() {
String s = "ciao";
assertEquals(s, "ciao");
}
}
If I run the following command: gradle test everything is ok. If I try to run the mainTests method from eclipse (right click on the method, Run As, JUnit test) I have the following exception:
Class not found it.main.tests.MainTest
java.lang.ClassNotFoundException: it.main.tests.MainTest
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:770)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:499)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:522)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
This is the build.gradle file:
apply plugin: 'java'
apply plugin: 'war'
sourceCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
}
compileJava {
options.fork = true
}
dependencies {
// Add all the jar dependencies from the lib folder.
compile fileTree(dir: 'src/main/webapp/WEB-INF/lib', include: ['*.jar'])
compile fileTree(dir: '//opt/jenkins/wcs_artifacts/WCS_trunk', include: ['beanstyler.jar', 'UnycoIntegrationBean.jar', 'UnycoModels.jar'])
compile group: 'javax.servlet', name: 'javax.servlet-api', version: '4.0.1'
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.11'
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: "5.2.0"
testCompile group: 'org.junit.platform', name: 'junit-platform-launcher', version: "1.2.0"
}
task createWCSAdminWar(type: War, dependsOn: [test, classes]) {
baseName = 'WCSAdmin'
destinationDir = file("$buildDir/dist")
}
task createUnycoAdminWar(type: War, dependsOn: [test, classes]) {
baseName = 'UnycoAdmin'
destinationDir = file("$buildDir/dist")
}
task createDists(dependsOn: [createWCSAdminWar, createUnycoAdminWar])
defaultTasks 'build'
And this is the .classpath file
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/UnycoIntegrationMessages"/>
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/UnycoModels"/>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="src" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>
Inside webapp/WEB-INF/lib/ I have the junit-4.12.jar file
Can anyone help me? Thanks

Testing with Gradle

Testing fails.
How fix exception?
Here is stacktrace and code:
Could not determine the dependencies of task ':test'.
Configuration with name 'default' not found.
My parent settings.gradle
rootProject.name = 'opti'
include 'web'
build.gradle
allprojects {
repositories {
mavenCentral()
}
group 'com.opti'
version '1.0'
apply plugin: 'java'
apply plugin: 'groovy'
dependencies {
testCompile 'org.codehaus.groovy:groovy-all:2.3.11',
'org.spockframework:spock-maven:0.7-groovy-2.0'
}
}
Tested module settings.gradle
rootProject.name = 'web'
include 'web'
build.gradle
group 'com.opti'
version '1.0'
apply plugin: 'groovy'
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile(project(':web'))
}
#Artur check that first:
https://docs.gradle.org/current/userguide/java_plugin.html
It seems that gradle could not find default configuration for web project.
You could also check if running this command helps
gradle :opti:test
or
gradle :web:test

How to fix this gradle dependency resolution error?

I am new to gradle and I am trying to use it for an existing java project.
I have created settings.gradle file in my root directory:
include ':datamodel'
include ':active'
include ':client'
include ':zero'
include ':toall'
and build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
}
}
The build.gradle in datamodel looks like this:
apply plugin: 'java'
sourceSets {
main.java.srcDirs = ['src/main/java']
main.resources.srcDirs = ['src/main/java']
test.java.srcDirs = ['tests/java']
test.resources.srcDirs = ['tests/resources']
}
dependencies {
compile 'com.google.protobuf:protobuf-java:2.5.+'
}
When I run gradle build (version: 2.0) I get this failure
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all dependencies for configuration ':datamodel:compile'.
> Could not find any version that matches com.google.protobuf:protobuf-java:2.5.+.
Required by:
MyRoot:datamodel:unspecified
How can I fix this?
Add
repositories {
mavenCentral()
}
to your build script. Not as a part of buildscript closure where you can define where to look for dependencies required to execute your build script. You can do it in your top-level build.gradle using
allprojects {
repositories {
mavenCentral()
}
}
Try this
compile 'com.google.protobuf:protobuf-java:2.5.0'
More info here
The maven repo looks like
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>2.5.0</version>
</dependency>
You can also try and add jcenter() to dependencies like this
dependencies {
mavenCentral()
jcenter()
}
which will allow to search not only in repo1.maven.org

Categories

Resources