Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradle Plugin: Calling apollo.customTypeMapping.put does nothing #2802

Closed
ansman opened this issue Dec 14, 2020 · 2 comments · Fixed by #2803
Closed

Gradle Plugin: Calling apollo.customTypeMapping.put does nothing #2802

ansman opened this issue Dec 14, 2020 · 2 comments · Fixed by #2803

Comments

@ansman
Copy link
Contributor

ansman commented Dec 14, 2020

Summary
Calling customTypeMapping.put without first calling set is ignored.

Version
2.4.6 (Gradle 6.7.1)

Description
To my surprise Gradle seems to ignore calls such as MapProperty.put if the property is not present. Here's some concrete examples:

apollo {
  // Prints `null`
  println(customTypeMapping.orNull)

  customTypeMapping.put("foo", "bar")
  // Prints `null`
  println(customTypeMapping.orNull)

  customTypeMapping.set(emptyMap())
  customTypeMapping.put("foo", "bar")
  // Prints `{foo=bar}`
  println(customTypeMapping.orNull)
}

The fix for this is simple, the Apollo Gradle Plugin just needs to set emptyMap() as the default value. Using convention does not work unfortunately.

The reason why I prefer put is because I often set up my Gradle scripts using custom Gradle plugins in buildSrc which can add some common default values.

@ansman
Copy link
Contributor Author

ansman commented Dec 14, 2020

This seems related to gradle/gradle#7485

@martinbonnin
Copy link
Contributor

martinbonnin commented Dec 14, 2020

Yup, this behaviour is super weird. Recent versions of Gradle have a MapProperty.convention() method that allows to set a default value and distinguish between empty vs unset. Tentative fix there: #2803

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants