Class: Buildr::Compiler::Javac
Overview
Javac compiler:
compile.using(:javac)
Used by default if .java files are found in the src/main/java directory (or src/test/java) and sets the target directory to target/classes (or target/test/classes).
Accepts the following options:
-
:warnings – Issue warnings when compiling. True when running in verbose mode.
-
:debug – Generates bytecode with debugging information. Set from the debug
environment variable/global option.
-
:deprecation – If true, shows deprecation messages. False by default.
-
:source – Source code compatibility.
-
:target – Bytecode compatibility.
-
:lint – Lint option is one of true, false (default), name (e.g. ‘cast’) or array.
-
:other – Array of options passed to the compiler
(e.g. [‘-implicit:none’, ‘-encoding’, ‘iso-8859-1’])
Constant Summary collapse
- OPTIONS =
[:warnings, :debug, :deprecation, :source, :target, :lint, :other]
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#compile(sources, target, dependencies) ⇒ Object
:nodoc:.
-
#initialize(project, options) ⇒ Javac
constructor
:nodoc:.
Methods inherited from Base
applies_to?, #dependencies, dependencies, #needed?, specify, to_sym
Constructor Details
Instance Method Details
#compile(sources, target, dependencies) ⇒ Object
:nodoc:
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/buildr/java/compiler.rb', line 55 def compile(sources, target, dependencies) #:nodoc: , OPTIONS cmd_args = [] # tools.jar contains the Java compiler. dependencies << Java.tools_jar if Java.tools_jar cmd_args << '-classpath' << dependencies.join(File::PATH_SEPARATOR) unless dependencies.empty? source_paths = sources.select { |source| File.directory?(source) } cmd_args << '-sourcepath' << source_paths.join(File::PATH_SEPARATOR) unless source_paths.empty? cmd_args << '-d' << File.(target) cmd_args += javac_args cmd_args += files_from_sources(sources) unless Buildr.application..dryrun trace((['javac'] + cmd_args).join(' ')) Java.load Java.com.sun.tools.javac.Main.compile(cmd_args.to_java(Java.java.lang.String)) == 0 or fail 'Failed to compile, see errors above' end end |