Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access to Project from Rules #23

Open
sebersole opened this issue May 7, 2018 · 3 comments
Open

Access to Project from Rules #23

sebersole opened this issue May 7, 2018 · 3 comments

Comments

@sebersole
Copy link
Contributor

I've run across a few cases already where access to the Project from Rules would be very nice.

@sebersole
Copy link
Contributor Author

@melix If I work on this and send you a PR would you integrate it? Is this something you are interested in continuing to support?

@melix
Copy link
Owner

melix commented May 9, 2018

I don't think it's a good idea to share the state of the Project. This has became a major problem in Gradle that the project can be mutated and accessed from anywhere, so it totally prevents from parallelizing, typically.

Instead, the pattern is to use class based actions and a configuration block that is the only one accessing the project state at some point in time, and pass the limited set of things it needs to the rule.

@sebersole
Copy link
Contributor Author

Ultimately, from my rules, I need access to my custom extension or a graph exposed from my extension. I had thought allowing access to the Project would be a nice generic solution. If you don't like that particular approach, that's fine.

Another option is to allow passing something other than Map<String,String> as arguments to the rule creation. As these ultimately get passed to the Gradle WorkExecutor stuff, those values really just need to be Serializable. IMO, the better solution would be to allow the rule to define a constructor like:

class MyRule implements ViolationRule {
    public MyRule(Serializable... args)
}

or at the very least (though definitely not as nice):

class MyRule implements ViolationRule {
    public MyRule(Map<String,Serializable> args)
}

Would you be on board with either of those?

If you don't like this second approach either, then what is your alternative approach? I need some form of a solution to this, so I'll either do the work here or fork this plugin and do it there

Well at the very least I need access to a custom Gradle extension object in my rules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants