AWS Community Day CPH - Three problems of Terraform
SF JUG - Gradle Lint
1. Netflix = freedom and responsibility
(The assignment operator is intentional)
2. What can Gradle Lint do?
4 Remove cruft
4 Bar practices that are universally bad
4 Sanitize dependencies
4 Keep Gradle version up-to-date
4 Auto-fix violations!
3. Gradle Lint in action
Apply it:
allprojects {
apply plugin: 'nebula.lint'
gradleLint.rules = ['dependency-parentheses', 'dependency-tuple', ...]
}
Run it:
./gradlew lintGradle
./gradlew build <-- also causes lintGradle to run
./gradlew fixGradleLint <-- fixes all problems for you
4. Unused dependencies
4 Remove unused first-order dependencies
4 Add transitive dependencies with compile time
references as first-order dependencies
4 Align fixed first-order dependency versions with
transitives when conflict resolved
4 Shuffle first-order dependencies to the correct
configurations (e.g. junit to testCompile)
5. Creating a simple lint rule
"All wars should be published to our binary
repository"
6. 1: Apply immediately after the war plugin
class AllWarsShouldBePublishedRule extends GradleLintRule {
@Override void visitApplyPlugin(MethodCallExpression call, String plugin) {
if(plugin == 'war') {
addLintViolation('WARs must be published')
.insertAfter(call, "apply plugin: 'netflix.war-publish'")
}
}
}
7. 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')) {
addLintViolation('WARs must be published')
.insertAfter(bookmark('applyWar'), "apply plugin: 'netflix.war-publish'")
}
}