Gradle task alias

1,421 views
Skip to first unread message

David Leangen

unread,
Mar 11, 2016, 9:27:55 AM3/11/16
to bndtool...@googlegroups.com

Hi!

My limited gradle experience is hindering my ability to solve what I thought should be a very simple problem I am trying to solve in my enRoute workspace.

In gradle, I want to create an “alias” for the build task. In my build.gradle file I have tried:

    task myAlias(dependsOn: build)

and just about every syntactical permutation I could think of. It seems that it is not the syntax that is the issue, but rather how the “build” task is defined. (Error log below)

Any suggestions from more experienced gradlers as to how I could achieve this?


Cheers,
=David



$ gradle tasks
:tasks

------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------

:tasks FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':tasks'.
Could not determine the dependencies of task ':bundle'.

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

BUILD FAILED

Relevant error in stack trace:

Caused by: org.gradle.api.UnknownTaskException: Task with path 'unspecified' not found in root project.


BJ Hargrave

unread,
Mar 11, 2016, 9:30:37 AM3/11/16
to bndtool...@googlegroups.com
There seems to more involved than what you describe in this email. Can you make a small github repo demonstrates the problem?


--
You received this message because you are subscribed to the Google Groups "bndtools-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bndtools-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David Leangen

unread,
Mar 11, 2016, 9:45:51 AM3/11/16
to bndtool...@googlegroups.com

Sure:



This is just an enRoute project archetype. You will find that the error still occurs if you add projects.

To reproduce, just run “gradle tasks”.


Cheers,
=David

BJ Hargrave

unread,
Mar 11, 2016, 10:06:35 AM3/11/16
to bndtool...@googlegroups.com
Well there are 2 problems I see in that repo. One is that there are zero Bnd projects in the repo. A Bnd project must have a bnd.bnd file. If I add an empty bnd.bnd file to cnf, then the workspace has one Bnd project which is cnf. The Bnd gradle plugin is only applied to Bnd projects.

The second issue is your "alias": `task myAlias(dependsOn: build)` is in the root project's build.gradle file. There is no build task in the root project. The build tasks exists in each subproject to which the Bnd gradle plugin is applied. Try moving that task into the subprojects {} section:

/* Configure the subprojects */
subprojects {
  def bndProject = bndWorkspace.getProject(name)
  if (bndProject != null) {
    plugins.apply 'biz.aQute.bnd'
    task myAlias(dependsOn: build) { }
  }
}

Notice that I also added {} to the task myAlias code since the task method requires a closure argument.

 $ ./gradlew --no-daemon
:cnf:myAlias
:cnf:compileJava UP-TO-DATE
:cnf:processResources UP-TO-DATE
:cnf:classes UP-TO-DATE
:cnf:jar UP-TO-DATE
:cnf:assemble UP-TO-DATE
:cnf:compileTestJava UP-TO-DATE
:cnf:processTestResources UP-TO-DATE
:cnf:testClasses UP-TO-DATE
:cnf:test UP-TO-DATE
:cnf:check SKIPPED
:cnf:build UP-TO-DATE
:cnf:myAlias UP-TO-DATE
BUILD SUCCESSFUL

David Leangen

unread,
Mar 11, 2016, 10:14:53 AM3/11/16
to bndtool...@googlegroups.com

Thank you, BJ. That indeed did the trick, and I learned some good stuff in the process. :-)

Much appreciated!

Cheers,
=David
Reply all
Reply to author
Forward
0 new messages