際際滷

際際滷Share a Scribd company logo
DISTRIBUTED
REFACTORING WITH
GRADLE LINT
Jon Schneider
Netflix Engineering Tools
@jon_k_schneider
GITHUB.COM/NETFLIXGRADLESUMMIT/LINT
GITHUB.COM/NETFLIXGRADLESUMMIT/LINT
NETFLIX IS KNOWN FOR
RAPID INNOVATION.
GITHUB.COM/NETFLIXGRADLESUMMIT/LINT
WE WANT TO MINIMIZE DRAG FROM LATE
ADOPTERS.
GITHUB.COM/NETFLIXGRADLESUMMIT/LINT
NETFLIX CULTURE IS
FREEDOM AND RESPONSIBILITY
GITHUB.COM/NETFLIXGRADLESUMMIT/LINT
GRADLE LINT
ALLOWS US TO
DISTRIBUTE
CHANGE.
GITHUB.COM/NETFLIXGRADLESUMMIT/LINT
THE UNUSED
DEPENDENCIES
RULE HELPS
MAINTAIN GOOD
DEPENDENCY
HYGIENE.
GITHUB.COM/NETFLIXGRADLESUMMIT/LINT
GRADLE LINT SUPPORTS
SHIPPING METRICS TO
nebula.metrics
GITHUB.COM/NETFLIXGRADLESUMMIT/LINT
CREATING A MORE COMPLEX RULE
"All wars should be published to our
binary repository"
GITHUB.COM/NETFLIXGRADLESUMMIT/LINT
1: APPLY IMMEDIATELY AFTER THE WAR
PLUGIN
class AllWarsShouldBePublishedRule extends GradleLintRule {
@Override void visitApplyPlugin(MethodCallExpression call, String plugin) {
if(plugin == 'war') {
addBuildLintViolation('WARs must be published', call)
.insertAfter(call, "apply plugin: 'netflix.war-publish'")
}
}
}
GITHUB.COM/NETFLIXGRADLESUMMIT/LINT
2: APPLY ONLY IF IT ISN'T ALREADY
APPLIED
class AllWarsShouldBePublishedRule extends GradleLintRule {
@Override void visitApplyPlugin(MethodCallExpression call, String plugin) {
if(plugin == 'war') bookmark('applyWar', call)
else if(plugin == 'netflix.war-publish') bookmark('applyWarPublish', call)
}
@Override protected void visitClassComplete(ClassNode node) {
if(bookmark('applyWar') && !bookmark('applyWarPublish')) {
addBuildLintViolation('WARs must be published', call)
.insertAfter(bookmark('applyWar'), "apply plugin: 'netflix.war-publish'")
}
}
}
GITHUB.COM/NETFLIXGRADLESUMMIT/LINT
3: REPLACE THE WAR PLUGIN ENTIRELY
class AllWarsShouldBePublishedRule extends GradleLintRule {
@Override void visitApplyPlugin(MethodCallExpression call, String plugin) {
if(plugin == 'war') bookmark('applyWar', call)
else if(plugin == 'netflix.war-publish') bookmark('applyWarPublish', call)
}
@Override protected void visitClassComplete(ClassNode node) {
if(bookmark('applyWar') && !bookmark('applyWarPublish')) {
addBuildLintViolation('WARs must be published', call)
.replaceWith(bookmark('applyWar'), "apply plugin: 'netflix.war-publish'")
}
}
}
GITHUB.COM/NETFLIXGRADLESUMMIT/LINT
4: BECOME GRADLE MODEL AWARE
class AllWarsShouldBePublishedRule extends GradleLintRule implements GradleModelAware {
@Override void visitApplyPlugin(MethodCallExpression call, String plugin) {
bookmark('lastApplyPlugin', call)
}
@Override protected void visitClassComplete(ClassNode node) {
if(project.plugins.hasPlugin(WarPlugin) &&
!project.plugins.hasPlugin('netflix.war-publish')) {
addBuildLintViolation('WARs must be published', call)
.insertAfter(
bookmark('lastApplyPlugin'),
"apply plugin: 'netflix.war-publish'"
)
}
}
}
GITHUB.COM/NETFLIXGRADLESUMMIT/LINT
GRADLE LINT IS OUR FIRST
DISTRIBUTED REFACTORING
TOOL.
GITHUB.COM/NETFLIXGRADLESUMMIT/LINT
THE EXPERIMENTAL LOCK PLUGIN IS
ANOTHER EXAMPLE.
github.com/nebula-plugins/lock-
experimental
GITHUB.COM/NETFLIXGRADLESUMMIT/LINT
WE WANT AN
EVENTUALLY CONSISTENT
MONOREPO
THROUGH
DISTRIBUTED REFACTORING.
GITHUB.COM/NETFLIXGRADLESUMMIT/LINT
JAVA POWER ASSERT WAS THE
LEARNING GROUND.
github.com/jkschneider/java-power-assert
GITHUB.COM/NETFLIXGRADLESUMMIT/LINT
THANK YOU.
GITHUB.COM/NETFLIXGRADLESUMMIT/LINT

More Related Content

Distributed Refactoring with Gradle Lint

  • 1. DISTRIBUTED REFACTORING WITH GRADLE LINT Jon Schneider Netflix Engineering Tools @jon_k_schneider GITHUB.COM/NETFLIXGRADLESUMMIT/LINT
  • 3. NETFLIX IS KNOWN FOR RAPID INNOVATION. GITHUB.COM/NETFLIXGRADLESUMMIT/LINT
  • 4. WE WANT TO MINIMIZE DRAG FROM LATE ADOPTERS. GITHUB.COM/NETFLIXGRADLESUMMIT/LINT
  • 5. NETFLIX CULTURE IS FREEDOM AND RESPONSIBILITY GITHUB.COM/NETFLIXGRADLESUMMIT/LINT
  • 6. GRADLE LINT ALLOWS US TO DISTRIBUTE CHANGE. GITHUB.COM/NETFLIXGRADLESUMMIT/LINT
  • 7. THE UNUSED DEPENDENCIES RULE HELPS MAINTAIN GOOD DEPENDENCY HYGIENE. GITHUB.COM/NETFLIXGRADLESUMMIT/LINT
  • 8. GRADLE LINT SUPPORTS SHIPPING METRICS TO nebula.metrics GITHUB.COM/NETFLIXGRADLESUMMIT/LINT
  • 9. CREATING A MORE COMPLEX RULE "All wars should be published to our binary repository" GITHUB.COM/NETFLIXGRADLESUMMIT/LINT
  • 10. 1: APPLY IMMEDIATELY AFTER THE WAR PLUGIN class AllWarsShouldBePublishedRule extends GradleLintRule { @Override void visitApplyPlugin(MethodCallExpression call, String plugin) { if(plugin == 'war') { addBuildLintViolation('WARs must be published', call) .insertAfter(call, "apply plugin: 'netflix.war-publish'") } } } GITHUB.COM/NETFLIXGRADLESUMMIT/LINT
  • 11. 2: APPLY ONLY IF IT ISN'T ALREADY APPLIED class AllWarsShouldBePublishedRule extends GradleLintRule { @Override void visitApplyPlugin(MethodCallExpression call, String plugin) { if(plugin == 'war') bookmark('applyWar', call) else if(plugin == 'netflix.war-publish') bookmark('applyWarPublish', call) } @Override protected void visitClassComplete(ClassNode node) { if(bookmark('applyWar') && !bookmark('applyWarPublish')) { addBuildLintViolation('WARs must be published', call) .insertAfter(bookmark('applyWar'), "apply plugin: 'netflix.war-publish'") } } } GITHUB.COM/NETFLIXGRADLESUMMIT/LINT
  • 12. 3: REPLACE THE WAR PLUGIN ENTIRELY class AllWarsShouldBePublishedRule extends GradleLintRule { @Override void visitApplyPlugin(MethodCallExpression call, String plugin) { if(plugin == 'war') bookmark('applyWar', call) else if(plugin == 'netflix.war-publish') bookmark('applyWarPublish', call) } @Override protected void visitClassComplete(ClassNode node) { if(bookmark('applyWar') && !bookmark('applyWarPublish')) { addBuildLintViolation('WARs must be published', call) .replaceWith(bookmark('applyWar'), "apply plugin: 'netflix.war-publish'") } } } GITHUB.COM/NETFLIXGRADLESUMMIT/LINT
  • 13. 4: BECOME GRADLE MODEL AWARE class AllWarsShouldBePublishedRule extends GradleLintRule implements GradleModelAware { @Override void visitApplyPlugin(MethodCallExpression call, String plugin) { bookmark('lastApplyPlugin', call) } @Override protected void visitClassComplete(ClassNode node) { if(project.plugins.hasPlugin(WarPlugin) && !project.plugins.hasPlugin('netflix.war-publish')) { addBuildLintViolation('WARs must be published', call) .insertAfter( bookmark('lastApplyPlugin'), "apply plugin: 'netflix.war-publish'" ) } } } GITHUB.COM/NETFLIXGRADLESUMMIT/LINT
  • 14. GRADLE LINT IS OUR FIRST DISTRIBUTED REFACTORING TOOL. GITHUB.COM/NETFLIXGRADLESUMMIT/LINT
  • 15. THE EXPERIMENTAL LOCK PLUGIN IS ANOTHER EXAMPLE. github.com/nebula-plugins/lock- experimental GITHUB.COM/NETFLIXGRADLESUMMIT/LINT
  • 16. WE WANT AN EVENTUALLY CONSISTENT MONOREPO THROUGH DISTRIBUTED REFACTORING. GITHUB.COM/NETFLIXGRADLESUMMIT/LINT
  • 17. JAVA POWER ASSERT WAS THE LEARNING GROUND. github.com/jkschneider/java-power-assert GITHUB.COM/NETFLIXGRADLESUMMIT/LINT