Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Migrating Nebula Plugins to the New Model and T...

Migrating Nebula Plugins to the New Model and TestKit

An overview of Nebula Gradle plugins for 2016. A little bit about moving some plugins to the new model. And a little of our experience switching from nebula-test to TestKit.

http://nebula-plugins.github.io/

Avatar for Rob Spieldenner

Rob Spieldenner

June 27, 2016
Tweet

More Decks by Rob Spieldenner

Other Decks in Programming

Transcript

  1. Migrating Nebula Plugins to the New Model and TestKit Rob

    Spieldenner @robspieldenner Netflix Engineering Tools Developer Productivity Team @NebulaPlugins http:/ /nebula-plugins.github.io/
  2. Nebula Gradle Plugins • http:/ /nebula- plugins.github.io/ • Netflix OSS

    developed gradle plugins http:/ /nebula-plugins.github.io/
  3. gradle-lint-plugin • Distributed refactoring • Show violations and fix them

    ./gradlew gradleLint ./gradlew fixGradleLint http:/ /nebula-plugins.github.io/
  4. gradle-resolution-rules- plugin • Reject netflix:mylibrary:2.0.1 When resolving a dynamic dependency

    evict this version from what is considered http:/ /nebula-plugins.github.io/
  5. gradle-resolution-rules- plugin • Align { "group": "com.amazonaws", "includes": ["aws-java-sdk.*"] }

    Make sure dependencies in a "family" are all at the same version http:/ /nebula-plugins.github.io/
  6. Other Nebula Plugins • gradle-dependency-lock-plugin • gradle-ospackage-plugin • nebula-publishing-plugin •

    gradle-metrics-plugin • gradle-info-plugin • ... many more http:/ /nebula-plugins.github.io/
  7. gradle-dependency-lock- plugin • Produce a lock file to get a

    reproducable resolve http:/ /nebula-plugins.github.io/
  8. gradle-ospackage-plugin • Create deb or rpm • Hook into daemontools

    and gradle application plugin http:/ /nebula-plugins.github.io/
  9. nebula-publishing-plugin • nebula.maven-publish or nebula.ivy-publish • add metadata to pom

    or descriptor • replace dynamic versions with resolved versions http:/ /nebula-plugins.github.io/
  10. gradle-metrics-plugin • metrics • failure/success • lint violations • plugin

    version • gradle version http:/ /nebula-plugins.github.io/
  11. Model Based Plugins • From: class MyPlugin implements Plugin<Project> {

    @Override void apply(Project project) {} } • To: class MyRules extends RuleSource { // @Model, @Mutate, @Defaults, etc. rules } http:/ /nebula-plugins.github.io/
  12. Excellent Replacement for Extensions @Managed interface MyDomain { String getProperty1()

    void setProperty1(String p) } http:/ /nebula-plugins.github.io/
  13. Excellent Replacement for Extensions class MyRules extends RuleSource { @Defaults

    void setDefaults(MyDomain domain) { domain.property1 = 'myproperty' } } http:/ /nebula-plugins.github.io/
  14. Task Creation Still Clear class MyRules extends RuleSource { @Mutate

    void addMyTask(ModelMap<Task> tasks, MyDomain domain) { tasks.create('myTask') { doLast { // work, have access to domain } } } } http:/ /nebula-plugins.github.io/
  15. Hybrid Solution class MyPlugin implements Project<Plugin> { @Override void apply(Project

    project) { project.plugins.apply(MyOtherPlugin) project.plugins.apply(MyRules) } static class MyRules extends RuleSource { // rules } } http:/ /nebula-plugins.github.io/
  16. Unit Tests • No changes def 'my test'() { def

    project = ProjectBuilder.builder() ./* various parameters*/.build() project.plugins.apply MyPlugin when: // manipulate some things then: // assert some things } http:/ /nebula-plugins.github.io/
  17. Functional Tests • Almost drop in replacement for IntegrationSpec •

    Need to remember to run pluginUnderTestMetadata task http:/ /nebula-plugins.github.io/
  18. Undecided on Run Helper def result = GradleRunner.create() .withProjectDir(projectDir) .withArguments('mytask')

    .withPluginClasspath() .build() vs def result = runTasksSuccessfully('mytask') http:/ /nebula-plugins.github.io/
  19. Excited for withGradleVersion def 'my test for gradle #gradleVersion'() {

    given: // setup when: def result = GradleRunner.create()./* omit for brevity*/ .withGradleVersion(gradleVersion).build() then: // assert some things where: gradleVersion << ['2.12', '2.13', '2.14', '3.0-milestone-2'] } http:/ /nebula-plugins.github.io/
  20. A Common Helper for Single Projects abstract class FunctionalSpec extends

    Specification { @Rule TestName testName = new TestName() File projectDir; File buildFile; File settingsFile def setup() { projectDir = new File("build/test/${this.class.canonicalName}/" + "${testName.methodName.replaceAll(/\W+/, '-')}") if (projectDir.exists()) { projectDir.deleteDir() } projectDir.mkdirs() buildFile = new File(projectDir, 'build.gradle.kts') settingsFile = new File(projectDir, 'settings.gradle') } } http:/ /nebula-plugins.github.io/
  21. A Common Helper for Multi- Projects abstract class MultiprojectFunctionalSpec extends

    FunctionalSpec { Map<String, Subproject> subprojects File addSubproject(String subprojectName) { // include in settings.gradle, add empty build.gradle(.kts) } File addSubproject(String subprojectName, String buildContents) { // call addSubproject(subprojectName) // set contents of build.gradle(.kts) } File getSubprojectDir(String subprojectName) File getSubprojectBuildFile(String subprojectName) } http:/ /nebula-plugins.github.io/
  22. What We're Still Using from Nebula Test Going Forward •

    New Helper Classes & Methods • The dependency creation logic (until we pull request a better version of it into TestKit) http:/ /nebula-plugins.github.io/
  23. What's Next • Moving plugins to Kotlin • Moving the

    rest of the plugins to TestKit • Continue evaluating the new model http:/ /nebula-plugins.github.io/