[GRADLE-3079] Method in build.gradle not available in imported scripts (regression in 1.12) Created: 29/Apr/14  Updated: 03/Jun/14  Resolved: 08/May/14

Status: Resolved
Project: Gradle
Affects Version/s: 1.12
Fix Version/s: 2.0-rc-1

Type: Bug
Reporter: René Gröschke (Inactive) Assignee: Luke Daley
Resolution: Fixed Votes: 4

Known Issue Of:

 Description   

when a method is defined in build.gradle, it's no longer available to the scripts that build.gradle includes.
Example:
-build.gradle-
void echo(String string)

{ logger.quiet string }


apply from: file('include.gradle')

-include.gradle-
task myTask

{ echo('this used to work') }

This used to work with version 1.11 (and since at least 1.1, which is the oldest Gradle version that I still had handy).



 Comments   
Comment by René Gröschke (Inactive) [ 29/Apr/14 ]

I wasn't able to use the "export to jira" link in our forum. that's why I created this issue manually.

Comment by Jamie Bisotti [ 07/May/14 ]

This is preventing my team/projects from upgrading Gradle to 1.12 as well.

Comment by Björn Kautler [ 03/Jun/14 ]

This is not only true in applied files, but also in subprojects.
I used to define a couple of methods in the root build file and call them from subprojects.
This stopped working in 1.12 as well.
But there - and I think also in the OPs case - an easy work-around is to use an ext-Variable with closure as value, so you change

void echo(String string) {
     logger.quiet string
}

to

ext.echo = { String string ->
     logger.quiet string
}

and everything works again.

Generated at Wed Jun 30 12:39:21 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.