Crimix / ChangedProjectsTaskPlugin

A Gradle plugin to run a user defined task on changed projects (modules) and their dependent projects (modules)
https://plugins.gradle.org/plugin/io.github.crimix.changed-projects-task
MIT License
8 stars 2 forks source link

Task '.run' not found in root project 'my-project'. #2

Open mklueh opened 2 years ago

mklueh commented 2 years ago

Hello,

first of all thank you, your plugin really does the job! I was trying to get something working for ages to release changed modules from my monorepo, but nothing really worked. In my opinion, especially after I've used https://nx.dev/ for my frontend project where it just takes one line of code to do the same without any plugins, I think it should be way easier with Gradle as well.

I just want to let one problem here, which is related to PowerShell and

FAILURE: Build failed with an exception.

* What went wrong:
Task '.run' not found in root project 'my-project'.

* Try:
> Run gradlew tasks to get a list of available tasks.
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2s

<-------------> 0% WAITING
> IDLE

when trying to run ./gradlew --continue runTaskForChangedProjects -PchangedProjectsTask.run with PowerShell

Crimix commented 2 years ago

That could sound like a PowerShell issue. Have you tried to to run it like this ./gradlew --continue runTaskForChangedProjects "-PchangedProjectsTask.run" to stop it parsing it.

mklueh commented 2 years ago

@Crimix thanks this helped.

I've discovered another problem.

My original command looked like this:

- name: Build Applications and push to Docker Registry
        run: >
          ./gradlew --continue -p applications build 
          -Dquarkus.container-image.build=true 
          -Dquarkus.container-image.push=true 
          -Dquarkus.package.type=native
          -Dquarkus.jib.base-registry-password=${{ secrets.GITHUB_TOKEN }} 
          -Dquarkus.jib.base-registry-username=${{ github.repository_owner }}

It seems putting these additional parameters behind this Gradle plugin will not pass them through to the actual task.

it basically does nothing

 ./gradlew --continue runTaskForChangedProjects -DchangedProjectsTask.run -Dquarkus.container-image.build=true -Dquarkus.container-image.push=true -Dquarkus.package.type=native
Configuration on demand is an incubating feature.

BUILD SUCCESSFUL in 4s

I also can't put them into the config

taskToRun = "build -Dquarkus.container-image.build=true -Dquarkus.container-image.push=true -Dquarkus.package.type=native" //One of the main use cases of the plugin
FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':runTaskForChangedProjects'.
> Task with path ':build -Dquarkus.container-image.build=true -Dquarkus.container-image.push=true -Dquarkus.package.type=native' not found in root project 'launchbase'.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s

What options are there to delegate the parameters?

Crimix commented 2 years ago

I designed the plugin mostly with testing in mind. The taskToRun is a single task that should exist in every subproject that gets run if files in that project is considered changed, it's not a command string (that just how Gradle works)

What are you trying to accomplish?

mklueh commented 2 years ago

My overall use case is maintaining and developing multiple applications in a monorepo and handling the build and deployment of applications automatically when the application modules or dependent library modules have changed

With regards to the parameters, I basically have different build behavior during CI vs local, and I do not want to put those properties into application.properties, but pass them into the task when calling it.

With that approach it is for example also possible to build one application normally, while the other is a native build.

Crimix commented 2 years ago

I just saw that in the command pasted here you used -D and not -P for my parameter. It needs to be a -P

./gradlew --continue runTaskForChangedProjects -PchangedProjectsTask.run -Dquarkus.container-image.build=true -Dquarkus.container-image.push=true -Dquarkus.package.type=native

mklueh commented 2 years ago

@Crimix thanks, you are right! It now works.

mklueh commented 2 years ago

However, the problem is, it now tries to build and deploy all dependent modules as well, not only the applications.

As stated here https://github.com/Crimix/ChangedProjectsTaskPlugin/issues/3 if there was a way to only execute the build commands for the application modules and let the library module builds getting handled with it instead of triggering build for each module on its own, it could work.

Other than that, I see no choice in removing the params and putting them into the application.properties files of the applications

Crimix commented 2 years ago

Are you using changedProjectsMode=ONLY_DIRECTLY?

Crimix commented 2 years ago

Or are I misunderstanding what you want.

Do you want changes to library modules that affect application modules to only build those application modules, sorta a "subprojectAllowList" where only subprojects on that list get the task executed even when other subprojects are changed?

mklueh commented 2 years ago

I basically want to replicate what I'd normally do with the plugin, just building the applications if they have changed. But I also want to build those applications, the library modules have changed from, but not the library modules themselves.

For what I understand, using the mode ONLY_DIRECTLY the plugin would not react to dependent modules at all, correct?

By the way, how do you usually test this plugin during development? Do you just push to maven local all the time or do you have it embedded in a buildSrc directory of another project? Wonder how I could easily debug into it

Crimix commented 2 years ago

I use the maven local way.

What it sounds to me is that you want a way to allow/deny projects from having the task to be run on them. Such that you can say "don't build the library projects themselves, but build those applications that depend on them".

This would be simple to add as a configuration

Crimix commented 2 years ago

Can you try version 1.3 where you specific your library projects in the new neverRunProject configuration option

mklueh commented 2 years ago

@Crimix thank you very much, amazing! I'll try it in the evening!