Reputation: 686
I am working on my first Java app. A co-worker started it but didn't have time to finish it. She is an experienced Java programmer, but I am not. However, the app is small enough that it seemed like a project I could take on as my first Java app (I do work with JVM languages such as Clojure, so I have some background exposure to the world of the JVM).
I am adding the ability to output our data as JSON. I would like to use Google's Gson class:
http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.google.code.gson%22
com.google.code.gson
My co-worker had no outside dependencies so she was simply compiling the code from the command line. Now that I am adding 3rd party dependencies, I thought I should switch to a build tool. I choose Buildr : http://buildr.apache.org/extending.html
I decided to download the 3 Jar files that constitute com.google.code.gson:
gson-2.2.4-javadoc.jar
gson-2.2.4-sources.jar
gson-2.2.4.jar
I am not sure how to include them in my Buildr project.
I used the "buildr" command to establish the default directories that Buildr prefers. But there is no obvious folder for 3rd party Jars.
I tried many variations of my build file. My latest iteration is:
# Version number for this release
VERSION_NUMBER = "1.0.0"
# Group identifier for your projects
GROUP = "buildr_fdg"
COPYRIGHT = "2014, Open"
GOOGLEGSON = ['gson-2.2.4-javadoc.jar', 'gson-2.2.4-sources.jar', 'gson-2.2.4.jar']
# Specify Maven 2.0 remote repositories here, like this:
repositories.remote << "http://repo1.maven.org/maven2"
desc "The Buildr_fdg project -- creating JSON object full of fake data since we don't have enough real data ."
define "buildr_fdg" do
project.version = VERSION_NUMBER
project.group = GROUP
manifest["Implementation-Vendor"] = COPYRIGHT
compile.with GOOGLEGSON
resources
test.compile.with # Add classpath dependencies
package(:jar)
end
But I get these errors:
buildr build
(in /Users/cerhov/projects/openz/lofdg/buildr_fdg, development)
Building buildr_fdg
Compiling buildr_fdg into /Users/cerhov/projects/openz/lofdg/buildr_fdg/target/classes
/Users/cerhov/projects/openz/lofdg/buildr_fdg/src/main/java/Main.java:8: package com.google.code does not exist
import com.google.code.*;
^
/Users/cerhov/projects/openz/lofdg/buildr_fdg/src/main/java/Main.java:27: cannot find symbol
symbol : class Gson
location: class com.company.Main
Gson gson = new GsonBuilder().setPrettyPrinting().create();
^
/Users/cerhov/projects/openz/lofdg/buildr_fdg/src/main/java/Main.java:27: cannot find symbol
symbol : class GsonBuilder
location: class com.company.Main
Gson gson = new GsonBuilder().setPrettyPrinting().create();
^
Note: /Users/cerhov/projects/openz/lofdg/buildr_fdg/src/main/java/Main.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
3 errors
Buildr aborted!
RuntimeError : Failed to compile, see errors above
(See full trace by running task with --trace)
cerhov : 15:33:25 : ~/projects/openz/lofdg/buildr_fdg $ buildr build
(in /Users/cerhov/projects/openz/lofdg/buildr_fdg, development)
Building buildr_fdg
Buildr aborted!
RuntimeError : Don't know how to build task '/Users/cerhov/projects/openz/lofdg/buildr_fdg/com.google.code.gson'
How do I tell Buildr about my 3rd party Jars?
Upvotes: 0
Views: 93
Reputation: 461
The simplest way to add dependencies to a Buildr project is to use the "maven" coordinates of the library. So I believe what you want to do is replace the GOOGLEGSON with something like
GOOGLEGSON = ['com.google.code.gson:gson:jar:2.2.4']
This combined with the reference to Maven central should mean that Buildr downloads the dependency and adds it to your classpath.
Upvotes: 2