gradle IntelliJ IDEA Task Customization

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Syntax

  • groovy.util.Node = node.find { childNode -> return true || false }
  • node.append(nodeYouWantAsAChild)
  • groovy.util.Node parsedNode = (new XmlParser()).parseText(someRawXMLString)
  • ''' mutli-line string (not interpolated) '''

Remarks

The three basic files of an IntelliJ project - the ipr, iws, and iml files - can be accessed as in gradle in the idea task through

project.ipr
module.iml
workspace.iws

using the .withXml lets you access the xml. Using the .asNode() on that turns it into a groovy xml node.

Ex:

project.ipr.withXml { provider ->
    def node = provider.asNode()

From there it's pretty simple - to modify gradle to configure IntelliJ projects for you, take the file as it starts, perform the actions you'd like gradle to take (inside IntelliJ), and then diff the new file with the old file. You should see what XML you'll need to customize the idea job. You'll also need to take note of where in the xml it's located.

One other thing to consider is that you don't want duplicate nodes within the IntelliJ files if you run the gradle idea multiple times. So, you'll want to search for the node you'd like to make and if it's not there, you can create and insert it.

Pitfalls:

Sometimes, when using == for string comparison in the find method, it fails. When testing and I find that to be the case, I use .contains.

When searching for nodes, not all nodes have the attribute you're using as a criteria, so be sure to check for null.



Got any gradle Question?