Search code examples
groovybuildr

Why is grep Failing to Find Matches on my Groovy Dependencies?


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 # => []

Solution

  • 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.