it
is the implicit variable of the surrounding closure. In your case, it
represents the implicit variable for closure dependency{}
which is incorrect. You would mean it
to be a variable representing each artifact from artifacts
.
Solution, use like below:
....
artifacts.each{ar ->
dependency{
groupId(ar.groupId)
}
}
......