Reputation: 1214
I'm editing an open source package which uses gradle for building/dependency management. I have not used gradle before.
I wanted to use a few jackson methods, so I added compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.7.5'
to the build.gradle
file and added import com.fasterxml.jackson.*;
to my project.
But when I try to build with ./gradle shadowJar
, I get the following error:
Installing pre-commit hook for Unix/OS X
WARNING: jar does not create an executable jar. Use shadowJar instead.
:compileJava
/Users/mttjone/sw/builds/bixie-vanilla/src/main/java/bixie/checker/reportprinter/JSONReportPrinter.java:11: error: package com.fasterxml.jackson does not exist
import com.fasterxml.jackson.*;
^
...
4 errors
:compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
By popular demand:
if(JavaVersion.current() < JavaVersion.VERSION_1_7){
println("\t************************")
println("\t*** Hello from Bixie ***")
println("\tYou will need Java 1.7 or higher if you want to continue.")
println("\tYour Java is really old. Found version " + JavaVersion.current())
println("\t************************")
throw new GradleException("Update your Java!")
}
import org.apache.tools.ant.taskdefs.condition.Os
//install the commit hook if possible.
def hook_folder = new File('./.git/hooks')
def hook = new File('pre-commit.sh')
def installed_hook = new File('./.git/hooks/pre-commit')
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
println("Installing pre-commit hook for WINDOWS")
if (hook.exists() && hook_folder.exists() && !installed_hook.exists()) {
exec {
commandLine 'cmd', '/c', 'copy', hook.getAbsolutePath(), installed_hook.getAbsolutePath()
}
}
} else {
println("Installing pre-commit hook for Unix/OS X")
if (hook.exists() && hook_folder.exists() && !installed_hook.exists()) {
exec {
workingDir '.'
commandLine 'cp', hook, installed_hook
}
}
}
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'idea'
apply plugin: 'jacoco'
apply plugin: 'com.github.kt3k.coveralls'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'application'
apply plugin: 'findbugs'
//apply plugin: 'jdepend'
apply plugin: 'checkstyle'
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
def version = '1.0'
jar.archiveName = "bixie_dyn.jar"
shadowJar.archiveName = "bixie.jar"
mainClassName = "bixie.Main"
repositories {
mavenCentral()
}
buildscript {
repositories {
mavenCentral()
maven {
name 'Shadow'
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.0.1'
classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.2'
}
}
configurations{
common
}
dependencies {
compile 'args4j:args4j:2.32'
compile 'log4j:log4j:1.2.17'
compile 'org.scala-lang:scala-actors:2.11.7'
compile 'org.scala-lang:scala-library:2.11.7'
compile 'com.googlecode.json-simple:json-simple:1.1.1'
compile 'net.sourceforge.findbugs:annotations:1.3.2'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.7.5'
compile fileTree(dir: 'lib', include: '*.jar')
testCompile "junit:junit:4.11" // Or whatever version
}
// building the jar ---------------------
jar {
println("WARNING: jar does not create an executable jar. Use shadowJar instead.")
baseName = 'bixie'
from configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
from('src/main/resources'){ include('log4j.properties')}
from('src/main/resources'){ include('basic_prelude.bpl')}
from('src/main/resources'){ include('java_lang.bpl')}
manifest {
attributes 'Main-Class': mainClassName,
'Class-Path': '.',
'Implementation-Title': 'Bixie',
'Implementation-Version': version
}
}
shadowJar {
append('src/main/resources/report_html.zip')
}
//jar.dependsOn shadowJar
// testing related activities -----------------
tasks.withType(FindBugs) {
effort = "max"
reportLevel = "medium"
findbugs.excludeFilter = file("$rootProject.projectDir/config/findbugs/excludeFilter.xml")
reports {
xml.enabled = false
html.enabled = true
}
}
jacocoTestReport {
reports {
xml.enabled true
html.enabled true
csv.enabled false
html.destination "${buildDir}/reports/coverage"
}
}
test {
jacoco {
enabled = true
}
testLogging {
events "failed"
exceptionFormat "full"
}
useJUnit()
}
task selfCheck {
group 'Verification'
description 'Run Bixie on itself.'
doLast {
def bixieJar = shadowJar.archivePath
def bixieDir = compileJava.destinationDir
def bixieClassPath = compileJava.classpath.asPath
//TODO generate this.
def bixieReportDir = "${buildDir}/reports/self_test.txt"
exec {
workingDir '.'
commandLine 'java', '-jar', bixieJar, '-j', bixieDir, '-cp', bixieClassPath, '-o', bixieReportDir, '-checker', '3'
}
}
}
task inferCheck {
group 'Verification'
description 'Run Facebook Infer on this project.'
doLast {
println("REQUIRES Infer TO BE IN YOUR PATH.")
exec {
workingDir '.'
commandLine 'infer', '--', 'gradle', 'clean', 'compileJava'
}
}
}
Relevant bit of gradle dependencies:
runtime - Runtime classpath for source set 'main'.
+--- args4j:args4j:2.32
+--- log4j:log4j:1.2.17
+--- org.scala-lang:scala-actors:2.11.7
| \--- org.scala-lang:scala-library:2.11.7
+--- org.scala-lang:scala-library:2.11.7
+--- com.googlecode.json-simple:json-simple:1.1.1
| \--- junit:junit:4.10
| \--- org.hamcrest:hamcrest-core:1.1
+--- net.sourceforge.findbugs:annotations:1.3.2
\--- com.fasterxml.jackson.core:jackson-databind:2.7.5
+--- com.fasterxml.jackson.core:jackson-annotations:2.7.0
\--- com.fasterxml.jackson.core:jackson-core:2.7.5
Upvotes: 1
Views: 2297
Reputation: 38619
I think your question has nothing to do with Gradle but just with getting your code corrected.
Does the package com.fasterxml.jackson
really exist?
Note, just that the package com.fasterxml.jackson.databind
or com.fasterxml.jackson.core
exist says nothing about the package com.fasterxml.jackson
. Those three packages are absolutely unrelated and standalone. There is no such thing like a "sub-package".
Upvotes: 1