Why is grep Failing to Find Matches on my Groovy Dependencies? [closed]
Does anyone know why the following code returns an empty array? Thanks.
groovyc_deps = Buildr::Groovy::Groovyc.dependencies
groovy_jar = groovyc_deps.grep /.*groovy.*\.jar/
p groovy_jar # => []
Because Groovyc.dependencies
returns an array of Artifact
, not Strings.
Try the following,
groovyc_deps = Buildr::Groovy::Groovyc.dependencies
groovy_jar = groovyc_deps.select { |a| a.to_s =~ /.*groovy.*\.jar/ }
which converts artifacts to string before matching against the regular expression.
精彩评论