TestsConfigurationPlugin.groovy 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright 2002-2017 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * https://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package io.spring.gradle.convention;
  17. import org.gradle.api.Plugin
  18. import org.gradle.api.Project
  19. import org.gradle.api.plugins.JavaPlugin
  20. import org.gradle.jvm.tasks.Jar
  21. /**
  22. * Adds the ability to depends on the test jar within other projects using:
  23. *
  24. * <code>
  25. * testCompile project(path: ':foo', configuration: 'tests')
  26. * </code>
  27. *
  28. * @author Rob Winch
  29. */
  30. public class TestsConfigurationPlugin implements Plugin<Project> {
  31. @Override
  32. public void apply(Project project) {
  33. project.plugins.withType(JavaPlugin) {
  34. applyJavaProject(project)
  35. }
  36. }
  37. private void applyJavaProject(Project project) {
  38. project.configurations {
  39. tests.extendsFrom testRuntime, testRuntimeClasspath
  40. }
  41. project.tasks.create('testJar', Jar) {
  42. archiveClassifier = 'test'
  43. from project.sourceSets.test.output
  44. }
  45. project.artifacts {
  46. tests project.testJar
  47. }
  48. }
  49. }