Class: Buildr::Groovy::Groovyc
- Inherits:
-
Compiler::Base
- Object
- Compiler::Base
- Buildr::Groovy::Groovyc
- Defined in:
- lib/buildr/groovy/compiler.rb
Overview
Groovyc compiler:
compile.using(:groovyc)
You need to require ‘buildr/groovy/compiler’ if you need to use this compiler.
Used by default if .groovy files are found in the src/main/groovy directory (or src/test/groovy) and sets the target directory to target/classes (or target/test/classes).
Groovyc is a joint compiler, this means that when selected for a project, this compiler is used to compile both groovy and java sources. It’s recommended that Groovy sources are placed in the src/main/groovy directory, even though this compiler also looks in src/main/java
Groovyc accepts the following options:
-
:encoding – Encoding of source files
-
:verbose – Asks the compiler for verbose output, true when running in verbose mode.
-
:fork – Whether to execute groovyc using a spawned instance of the JVM; defaults to no
-
:memoryInitialSize – The initial size of the memory for the underlying VM, if using fork mode; ignored otherwise.
Defaults to the standard VM memory setting. (Examples: 83886080, 81920k, or 80m)
-
:memoryMaximumSize – The maximum size of the memory for the underlying VM, if using fork mode; ignored otherwise.
Defaults to the standard VM memory setting. (Examples: 83886080, 81920k, or 80m)
-
:listfiles – Indicates whether the source files to be compiled will be listed; defaults to no
-
:stacktrace – If true each compile error message will contain a stacktrace
-
: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.
-
:optimise – Generates faster bytecode by applying optimisations to the program.
-
:source – Source code compatibility.
-
:target – Bytecode compatibility.
-
:javac – Hash of options passed to the ant javac task
Constant Summary collapse
- REQUIRES =
The groovyc compiler jars are added to classpath at load time, if you want to customize artifact versions, you must set them on the
artifact_ns['Buildr::Compiler::Groovyc'].groovy = '1.5.4'
namespace before this file is required.
ArtifactNamespace.for(self) do |ns| ns.groovy! 'org.codehaus.groovy:groovy:jar:>=1.5.3' ns.commons_cli! 'commons-cli:commons-cli:jar:>=1.0' ns.asm! 'asm:asm:jar:>=2.2' ns.antlr! 'antlr:antlr:jar:>=2.7.7' end
- ANT_TASK =
'org.codehaus.groovy.ant.Groovyc'
- GROOVYC_OPTIONS =
[:encoding, :verbose, :fork, :memoryInitialSize, :memoryMaximumSize, :listfiles, :stacktrace]
- JAVAC_OPTIONS =
[:optimise, :warnings, :debug, :deprecation, :source, :target, :javac]
- OPTIONS =
GROOVYC_OPTIONS + JAVAC_OPTIONS
Instance Attribute Summary
Attributes inherited from Compiler::Base
Class Method Summary collapse
-
.applies_to?(project, task) ⇒ Boolean
:nodoc:.
-
.dependencies ⇒ Object
:nodoc:.
Instance Method Summary collapse
- #compile(sources, target, dependencies) ⇒ Object
-
#initialize(project, options) ⇒ Groovyc
constructor
:nodoc:.
Methods inherited from Compiler::Base
#dependencies, #needed?, specify, to_sym
Constructor Details
#initialize(project, options) ⇒ Groovyc
:nodoc:
89 90 91 92 93 94 95 96 97 |
# File 'lib/buildr/groovy/compiler.rb', line 89 def initialize(project, ) #:nodoc: super [:debug] = Buildr..debug if [:debug].nil? [:deprecation] ||= false [:optimise] ||= false [:verbose] ||= Buildr.application..trace if [:verbose].nil? [:warnings] = verbose if [:warnings].nil? [:javac] = OpenObject.new if [:javac].nil? end |
Class Method Details
.applies_to?(project, task) ⇒ Boolean
:nodoc:
76 77 78 79 80 81 |
# File 'lib/buildr/groovy/compiler.rb', line 76 def applies_to?(project, task) #:nodoc: paths = task.sources + [sources].flatten.map { |src| Array(project.path_to(:source, task.usage, src.to_sym)) } paths.flatten! # Just select if we find .groovy files paths.any? { |path| !Dir["#{path}/**/*.groovy"].empty? } end |
.dependencies ⇒ Object
:nodoc:
72 73 74 |
# File 'lib/buildr/groovy/compiler.rb', line 72 def dependencies #:nodoc: REQUIRES.artifacts end |
Instance Method Details
#compile(sources, target, dependencies) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/buildr/groovy/compiler.rb', line 100 def compile(sources, target, dependencies) #:nodoc: return if Buildr.application..dryrun Buildr.ant 'groovyc' do |ant| classpath = dependencies ant.taskdef :name => 'groovyc', :classname => ANT_TASK, :classpath => classpath.join(File::PATH_SEPARATOR) ant.groovyc (sources, target) do sources.each { |src| ant.src :path => src } ant.classpath do classpath.each { |dep| ant.pathelement :path => dep } end ant.javac() end end end |