Setting upload repositories in afterEvaluate vs. toolingapi


(Marwin) #1

Hi,
I’ve been using gradle for quite some time but today I ran into some behavior that I’m not sure whether it is expected. And if so, I’d appreciate some advice.

Summary:
If uploadArchives.repositories are configured in afterEvaluate, the Eclipse integration plugin (STS) is unable to “remap” gradle projects - I suspect because toolingapi does not return a proper GradlePublication for such a project.

Situation:
I’m using my own plugin that is configured with an extension/convention object. Based on such configuration, the plugin selects a repository for upload. To be able to process the configuration, almost all the plugin’s work is done in afterEvaluate.
When a project that uses this plugin is imported into Eclipse with eclipse-integration-gradle plugin (“Gradle STS”), the plugin’s “remap jars to gradle projects” functionality does not work.
After some investigation, I found out that it is because of uploadArchives being configured in afterEvaluate.

More precisly:
uploadArchives { repositories { ... } }
works fine but when it gets changed to
afterEvaluate { uploadArchives { repositories { ... } } }
the project does not “publish” it’s jars correctly. Well, the JARs will get uploaded (published) to artifactory but Eclipse does not see them. I believe the toolingapi does not return anything in ProjectPublications, but I did not debug it in detail.

Questions:

  1. If some plugin wants to process configuration in it’s extension object, can it be done anywhere else than in project’s afterEvaluate?
  2. Is it legal to manipulate uploadArchives (and namely it’s repositories) in afterEvaluate? By the way, the same question can be asked for changing dependencies, source sets etc. Are there some limitations of using afterEvaluate?
  3. If answer to both the above question is “no”, how can I write a plugin that can be configured to add upload repositories?
  4. The toolingapi (presumably) returns a different result when something is done directly in the script or inside afterEvalute. Should this be considered a bug?

Thanks for any help.