Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.3.1, 1.3.2
-
None
Description
When using option to create buildfile from maven2 pom I got the following error (after I turned on trace)
rake aborted!
undefined method `find' for nil:NilClass
/usr/local/jruby-1.1.3/lib/ruby/gems/1.8/gems/buildr-1.3.2-java/lib/buildr/core/generate.rb:153:in `from_maven2_pom'
After looking into the issue I found that the code in question was the following:
plugins = project['build'].first['plugins'].first['plugin'] rescue {}
compile_plugin = plugins.find
if compile_plugin
source = compile_plugin.first['configuration'].first['source'] rescue nil
target = compile_plugin.first['configuration'].first['target'] rescue nil
script << " compile.options.source = '#{source}'" if source
script << " compile.options.target = '#{target}'" if target
end
my projects use a parent pom which specifies some of the plugins, so I think that some of them may not have any. All I did for a fix was to wrap with the test for nil. While this worked for me (at least to create my buildfile). I am just starting to learn the source, so this patch will need a more expert opinion.
plugins = project['build'].first['plugins'].first['plugin'] rescue {}
if plugins != nil
compile_plugin = plugins.find{|pl| (pl['groupId'].nil? or pl['groupId'].first == 'org.apache.maven.plugins') and pl['artifactId'].first == 'maven-compiler-plugin'}
if compile_plugin
source = compile_plugin.first['configuration'].first['source'] rescue nil
target = compile_plugin.first['configuration'].first['target'] rescue nil
script << " compile.options.source = '#
{source}'" if source
script << " compile.options.target = '#
'" if target
end
end