Egor Erofeev
Egor Erofeev

Reputation: 137

Gradle: create a single JAR with dependencies

I am migrating our product's build from Ant to Gradle, having started from a single project and got the following error:

> Could not resolve all files for configuration ':Shared:serverbase:compileClasspath'.
   > Could not find guava:guava:23.3-jre.
     Searched in the following locations:
       - https://jcenter.bintray.com/guava/guava/23.3-jre/guava-23.3-jre.pom
       - file:/F:/pros/X/java/guava/guava-23.3-jre.xml
     Required by:
         project :Shared:serverbase

Why it is looking for xml-files instead of jar?

Here are my files: build.gradle in project's root directory:

buildscript {
    repositories {
        jcenter()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6' // gwt compiler plugin
    }
}

allprojects {

    apply from: rootProject.file('libraries.gradle')
    repositories {
        jcenter()
        ivy {
            url  "file://${rootProject.projectDir}/ThirdParty/java/"
            patternLayout  {
                artifact "[organization]/[module](-[revision])(.[ext])"
            }
        }
    }
}

subprojects {
    apply plugin: 'java-library'

    sourceCompatibility = '1.8'
    targetCompatibility = '1.8'


    compileJava.options.debugOptions.debugLevel = "lines,vars,source"
    compileJava.options.compilerArgs += ["-nowarn"]
    compileJava.options.debug = true
}

build.gradle of this single project:

sourceSets.main.java.srcDirs = ['src']

dependencies {
    implementation "guava:guava:${guavaVersion}"
    implementation "slf4j:jul-to-slf4j:${slf4jVersion}"
    implementation "logback:logback-classic:${logbackVersion}"

}

jar {
    manifest {
        attributes 'Class-Path': configurations.compileClasspath.collect { it.getName() }.join(' ')
    }        

}

settings.gradle:

rootProject.name = 'X'
include 'Shared:serverbase'

libraries.gradle:

ext {
...
    guavaVersion = '23.3-jre'
...
}

(some content stripped)

And if I add file dependency to build.gradle as local file (How to add local .jar file dependency to build.gradle file?)

implementation files("guava-${guavaVersion}.jar")

I got tons of errors like 'error: package org.slf4j does not exist' so it seems that dependencies were not satisfied at all. The outcome should be a single jar with compiled sources.

I am a novice in gradle, please forgive my unenlightenment.

Upvotes: 1

Views: 264

Answers (1)

pczeus
pczeus

Reputation: 7868

Your Guava dependency is not correct.

Change from:

implementation "guava:guava:${guavaVersion}"

To:

implementation "com.google.guava:guava:${guavaVersion}"

Upvotes: 1

Related Questions