|
| 1 | +package org.gradlex.javamodule.dependencies.test |
| 2 | + |
| 3 | +import org.gradlex.javamodule.dependencies.test.fixture.GradleBuild |
| 4 | +import spock.lang.Specification |
| 5 | + |
| 6 | +class ConfigurationCacheTest extends Specification { |
| 7 | + |
| 8 | + @Delegate |
| 9 | + GradleBuild build = new GradleBuild() |
| 10 | + |
| 11 | + def "configurationCacheHit"() { |
| 12 | + given: |
| 13 | + libModuleInfoFile << 'module abc.lib { }' |
| 14 | + appModuleInfoFile << ''' |
| 15 | + module abc.app { |
| 16 | + requires abc.lib; |
| 17 | + } |
| 18 | + ''' |
| 19 | + |
| 20 | + |
| 21 | + def runner = runner(':app:compileJava') |
| 22 | + when: |
| 23 | + def result = runner.build() |
| 24 | + |
| 25 | + then: |
| 26 | + result.getOutput().contains("Calculating task graph as no cached configuration is available for tasks: :app:compileJava") |
| 27 | + |
| 28 | + when: |
| 29 | + result = runner.build() |
| 30 | + |
| 31 | + then: |
| 32 | + result.getOutput().contains("Reusing configuration cache.") |
| 33 | + } |
| 34 | + |
| 35 | + def "configurationCacheHitIrrelevantChange"() { |
| 36 | + libModuleInfoFile << 'module abc.lib { }' |
| 37 | + appModuleInfoFile << ''' |
| 38 | + module abc.app { |
| 39 | + requires abc.lib; |
| 40 | + } |
| 41 | + ''' |
| 42 | + |
| 43 | + def runner = runner(':app:compileJava') |
| 44 | + when: |
| 45 | + def result = runner.build() |
| 46 | + |
| 47 | + then: |
| 48 | + result.getOutput().contains("Calculating task graph as no cached configuration is available for tasks: :app:compileJava") |
| 49 | + |
| 50 | + when: |
| 51 | + appModuleInfoFile.write(''' |
| 52 | + module abc.app { |
| 53 | + requires abc.lib; //This is a comment and should not break the configurationCache |
| 54 | + } |
| 55 | + ''') |
| 56 | + result = runner.build() |
| 57 | + |
| 58 | + then: |
| 59 | + result.getOutput().contains("Reusing configuration cache.") |
| 60 | + } |
| 61 | + |
| 62 | + def "configurationCacheHitRelevantChange"() { |
| 63 | + given: |
| 64 | + libModuleInfoFile << 'module abc.lib { }' |
| 65 | + appModuleInfoFile << ''' |
| 66 | + module abc.app { |
| 67 | + requires abc.lib; |
| 68 | + } |
| 69 | + ''' |
| 70 | + |
| 71 | + def runner = runner(':app:compileJava') |
| 72 | + when: |
| 73 | + def result = runner.build() |
| 74 | + |
| 75 | + then: |
| 76 | + result.getOutput().contains("Calculating task graph as no cached configuration is available for tasks: :app:compileJava") |
| 77 | + |
| 78 | + when: |
| 79 | + appModuleInfoFile.write(''' |
| 80 | + module abc.app { |
| 81 | + //dependency removed; so thats indeed a configuration change |
| 82 | + } |
| 83 | + ''') |
| 84 | + result = runner.build() |
| 85 | + |
| 86 | + then: |
| 87 | + result.output.contains("Calculating task graph as configuration cache cannot be reused because a build logic input of type 'ValueSourceModuleInfo' has changed.\n") |
| 88 | + } |
| 89 | + |
| 90 | +} |
0 commit comments