-
-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: compileOnly dependencies are not visible to the test compile cla…
…sspath.
- Loading branch information
1 parent
55377ea
commit 97cb447
Showing
5 changed files
with
156 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...alTest/groovy/com/autonomousapps/jvm/projects/CompileOnlyTestImplementationProject.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package com.autonomousapps.jvm.projects | ||
|
||
import com.autonomousapps.AbstractProject | ||
import com.autonomousapps.kit.GradleProject | ||
import com.autonomousapps.kit.Source | ||
import com.autonomousapps.model.ProjectAdvice | ||
|
||
import static com.autonomousapps.AdviceHelper.actualProjectAdvice | ||
import static com.autonomousapps.AdviceHelper.emptyProjectAdviceFor | ||
import static com.autonomousapps.kit.gradle.dependencies.Dependencies.commonsCollections | ||
|
||
/** | ||
* The {@code testImplementation} configuration does not extend from the {@code compileOnly} configuration. So, it is | ||
* inaccurate to suggest removing {@code testImplementation} dependencies just because they're on the compile classpath. | ||
* | ||
* @see <a href="https://docs.gradle.org/current/userguide/java_plugin.html#resolvable_configurations">Java configurations</a> | ||
*/ | ||
final class CompileOnlyTestImplementationProject extends AbstractProject { | ||
|
||
final GradleProject gradleProject | ||
|
||
CompileOnlyTestImplementationProject() { | ||
this.gradleProject = build() | ||
} | ||
|
||
private GradleProject build() { | ||
return newGradleProjectBuilder() | ||
.withSubproject('lib') { s -> | ||
s.sources = SOURCES | ||
s.withBuildScript { bs -> | ||
bs.plugins = javaLibrary | ||
bs.dependencies = [ | ||
// These two configurations are independent! | ||
commonsCollections('compileOnly'), | ||
commonsCollections('testImplementation'), | ||
] | ||
} | ||
} | ||
.write() | ||
} | ||
|
||
private static final List<Source> SOURCES = [ | ||
Source.java( | ||
'''\ | ||
package com.example.lib; | ||
import org.apache.commons.collections4.Bag; | ||
import org.apache.commons.collections4.bag.HashBag; | ||
public class Lib { | ||
private Bag<String> newBag() { | ||
return new HashBag<>(); | ||
} | ||
} | ||
''' | ||
) | ||
.withPath('com.example.lib', 'Lib') | ||
.build(), | ||
Source.java( | ||
'''\ | ||
package com.example.lib; | ||
import org.apache.commons.collections4.Bag; | ||
import org.apache.commons.collections4.bag.HashBag; | ||
public class LibTest { | ||
private void test() { | ||
Bag<String> bag = new HashBag<>(); | ||
} | ||
} | ||
''' | ||
) | ||
.withPath('com.example.lib', 'LibTest') | ||
.withSourceSet('test') | ||
.build(), | ||
] | ||
|
||
Set<ProjectAdvice> actualBuildHealth() { | ||
return actualProjectAdvice(gradleProject) | ||
} | ||
|
||
final Set<ProjectAdvice> expectedBuildHealth = [ | ||
emptyProjectAdviceFor(':lib'), | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters