11

We're using the Gradle Wrapper for all of our projects but one of our tools (IntelliJ IDEA) frequently re-runs the wrapper task which changes the first line - a comment about when the file was generated - every time it's run. This change has a tendency to be added to pull requests meaning that there's a high potential for unnecessary merge conflicts.

The proper solution would be to have all developers never check in the file unless it has actually changed in a meaningful way, but developers (me included) can be hasty and forgetful so the file shows up regularly in pull requests.

I've had a few ideas to solve this but can't really decide on any of them.

  1. Make Git ignore the first line of gradle-wrapper.properties like this, feels cumbersome and will have to be done by every developer since it's local.

  2. Add a tail to the gradle wrapper task that removes the first line of gradle-wrapper.properties, feels a bit hackish.

  3. Somehow make IDEA not re-run the wrapper task automatically every time we sync the project, no idea how to do this.

I'm leaning towards 2. right now but I'd like to hear if anyone else have any better ideas.

Community
  • 1
  • 1
Raniz
  • 10,882
  • 1
  • 32
  • 64
  • 2
    How often are you running the Gradle wrapper task, and why? It only needs to be run when you want to update the version of the provided Gradle install. I have never seen IntelliJ do this without explicitly running the wrapper task. – cjstehno Mar 11 '16 at 13:16
  • IDEA runs the wrapper task before synchronising the project which we have to do every time we update or add dependencies (which happens often since we use internal libraries for sharing data models and some utility code). IDEA is configured to use the wrapper when we import the project as a Gradle project. – Raniz Mar 14 '16 at 07:36
  • I wonder if it's a setting when you first open the project - when I open a Gradle project for the first time I use File > Open and then accept the defaults - maybe you are changing one of these. I will have to open a new project and see what the options are. What are describing is not the default behavior in general. I use Git+Gradle+Intellij and have never run into this. – cjstehno Mar 14 '16 at 12:28

1 Answers1

10

It seems that selecting Use the default Gradle wrapper is the correct option to choose when importing a Gradle project and that Use customizable gradle wrapper (Gradle wrapper customization in script, works with Gradle 1.7 or later) is the option that causes IDEA to re-run the wrapper task all the time.

Raniz
  • 10,882
  • 1
  • 32
  • 64
  • 1
    Does this still hold? I cannot fix the issue by merely selecting default Gradle wrapper when importing. Intellij updates the time in gradle-wrapper.properties everytime I run gradle wrapper, even when default wrapper is selected. – bengro Feb 08 '17 at 23:47
  • I'm still doing it like this in IDEA 2016.3 – Raniz Feb 09 '17 at 12:23
  • Ok, good to know, thanks. ./gradlew wrapper also generates the dates, hence this might be a gradle issue. I'll keep investigating. – bengro Feb 10 '17 at 13:36
  • 1
    `./gradlew wrapper` is supposed to update the dates since it's regenerating the files. The only time you should be running `./gradlew wrapper`is if you've updated the version of the wrapper. My issue was that IDEA kept running `./gradlew wrapper` everytime I refreshed the project – Raniz Aug 31 '17 at 06:51