-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For Maven, if a dependency with runtime and test, a runtime dependenc…
…y is added (#2683)
- Loading branch information
Showing
5 changed files
with
156 additions
and
9 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
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
65 changes: 65 additions & 0 deletions
65
starter-core/src/test/groovy/io/micronaut/starter/build/maven/MavenDependencySpec.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,65 @@ | ||
package io.micronaut.starter.build.maven | ||
|
||
import io.micronaut.starter.BeanContextSpec | ||
import io.micronaut.starter.application.generator.DependencyContextImpl | ||
import io.micronaut.starter.build.dependencies.CoordinateResolver | ||
import io.micronaut.starter.build.dependencies.Dependency | ||
import io.micronaut.starter.build.dependencies.DependencyContext | ||
import io.micronaut.starter.build.dependencies.Scope | ||
import io.micronaut.starter.fixture.CommandOutputFixture | ||
import io.micronaut.starter.options.BuildTool | ||
import io.micronaut.starter.options.Language | ||
|
||
class MavenDependencySpec extends BeanContextSpec implements CommandOutputFixture { | ||
|
||
public static final String ARTIFACT_ID_LOGBACK_CLASSIC = "logback-classic" | ||
public static final String GROUP_ID_LOGBACK = "ch.qos.logback" | ||
|
||
void "maven dependency in test and runtime should be only in compile"() { | ||
given: | ||
CoordinateResolver coordinateResolver = beanContext.getBean(CoordinateResolver) | ||
DependencyContext dependencyContext = new DependencyContextImpl(coordinateResolver) | ||
|
||
when: | ||
List<Dependency> dependencies = dependencyContext.removeDuplicates(List.of( | ||
Dependency.builder().scope(Scope.COMPILE).groupId(GROUP_ID_LOGBACK).artifactId(ARTIFACT_ID_LOGBACK_CLASSIC).build(), | ||
Dependency.builder().scope(Scope.RUNTIME).groupId(GROUP_ID_LOGBACK).artifactId(ARTIFACT_ID_LOGBACK_CLASSIC).build(), | ||
), Language.JAVA, BuildTool.MAVEN) | ||
|
||
then: | ||
dependencies == List.of( | ||
Dependency.builder().scope(Scope.COMPILE).groupId(GROUP_ID_LOGBACK).artifactId(ARTIFACT_ID_LOGBACK_CLASSIC).build()) | ||
|
||
when: | ||
dependencies = dependencyContext.removeDuplicates(List.of( | ||
Dependency.builder().scope(Scope.TEST).groupId(GROUP_ID_LOGBACK).artifactId(ARTIFACT_ID_LOGBACK_CLASSIC).build(), | ||
Dependency.builder().scope(Scope.RUNTIME).groupId(GROUP_ID_LOGBACK).artifactId(ARTIFACT_ID_LOGBACK_CLASSIC).build(), | ||
), Language.JAVA, BuildTool.GRADLE) | ||
|
||
then: | ||
dependencies == List.of( | ||
Dependency.builder().scope(Scope.RUNTIME).groupId(GROUP_ID_LOGBACK).artifactId(ARTIFACT_ID_LOGBACK_CLASSIC).build(), | ||
Dependency.builder().scope(Scope.TEST).groupId(GROUP_ID_LOGBACK).artifactId(ARTIFACT_ID_LOGBACK_CLASSIC).build(), | ||
) | ||
|
||
when: | ||
dependencies = dependencyContext.removeDuplicates(List.of( | ||
Dependency.builder().scope(Scope.TEST).groupId(GROUP_ID_LOGBACK).artifactId(ARTIFACT_ID_LOGBACK_CLASSIC).build(), | ||
Dependency.builder().scope(Scope.RUNTIME).groupId(GROUP_ID_LOGBACK).artifactId(ARTIFACT_ID_LOGBACK_CLASSIC).build(), | ||
), Language.JAVA, BuildTool.MAVEN) | ||
|
||
then: | ||
dependencies == List.of( | ||
Dependency.builder().scope(Scope.RUNTIME).groupId(GROUP_ID_LOGBACK).artifactId(ARTIFACT_ID_LOGBACK_CLASSIC).build()) | ||
|
||
when: | ||
dependencies = dependencyContext.removeDuplicates(List.of( | ||
Dependency.builder().scope(Scope.COMPILE).groupId(GROUP_ID_LOGBACK).artifactId(ARTIFACT_ID_LOGBACK_CLASSIC).build(), | ||
Dependency.builder().scope(Scope.RUNTIME).groupId(GROUP_ID_LOGBACK).artifactId(ARTIFACT_ID_LOGBACK_CLASSIC).build(), | ||
), Language.JAVA, BuildTool.MAVEN) | ||
|
||
then: | ||
dependencies == List.of( | ||
Dependency.builder().scope(Scope.COMPILE).groupId(GROUP_ID_LOGBACK).artifactId(ARTIFACT_ID_LOGBACK_CLASSIC).build()) | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...e/src/test/groovy/io/micronaut/starter/feature/logging/LogbackInTestAndRuntimeSpec.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,66 @@ | ||
package io.micronaut.starter.feature.logging | ||
|
||
import io.micronaut.context.annotation.Requires | ||
import io.micronaut.starter.ApplicationContextSpec | ||
import io.micronaut.starter.BuildBuilder | ||
import io.micronaut.starter.application.ApplicationType | ||
import io.micronaut.starter.application.generator.GeneratorContext | ||
import io.micronaut.starter.build.BuildTestUtil | ||
import io.micronaut.starter.build.BuildTestVerifier | ||
import io.micronaut.starter.build.dependencies.Dependency | ||
import io.micronaut.starter.build.dependencies.Scope | ||
import io.micronaut.starter.feature.Feature | ||
import io.micronaut.starter.fixture.CommandOutputFixture | ||
import io.micronaut.starter.options.BuildTool | ||
import io.micronaut.starter.options.Language | ||
import jakarta.inject.Singleton | ||
|
||
class LogbackInTestAndRuntimeSpec extends ApplicationContextSpec implements CommandOutputFixture { | ||
private static final String ARTIFACT_ID_LOGBACK_CLASSIC = "logback-classic" | ||
private static final String GROUP_ID_LOGBACK = "ch.qos.logback" | ||
|
||
Map<String, Object> getConfiguration() { | ||
return super.getConfiguration() + ["spec.name": "LogbackInTestAndRuntimeSpec"] | ||
} | ||
|
||
void "compile if runtime and test dependency"() { | ||
given: | ||
BuildTool buildTool = BuildTool.MAVEN | ||
Language language = Language.JAVA | ||
when: | ||
String template = new BuildBuilder(beanContext, buildTool) | ||
.language(language) | ||
.features(["test-logback"]) | ||
.render() | ||
BuildTestVerifier verifier = BuildTestUtil.verifier(buildTool, language, template) | ||
|
||
then: | ||
verifier.hasDependency(GROUP_ID_LOGBACK, ARTIFACT_ID_LOGBACK_CLASSIC, Scope.RUNTIME) | ||
!verifier.hasDependency(GROUP_ID_LOGBACK, ARTIFACT_ID_LOGBACK_CLASSIC, Scope.TEST) | ||
} | ||
|
||
@Requires(property = "spec.name", value = "LogbackInTestAndRuntimeSpec") | ||
@Singleton | ||
static class TestLogback implements Feature { | ||
|
||
@Override | ||
String getName() { | ||
return "test-logback" | ||
} | ||
|
||
@Override | ||
String getTitle() { | ||
return "Test Logback" | ||
} | ||
|
||
@Override | ||
void apply(GeneratorContext generatorContext) { | ||
generatorContext.addDependency(Dependency.builder().groupId(GROUP_ID_LOGBACK).artifactId(ARTIFACT_ID_LOGBACK_CLASSIC).scope(Scope.TEST).build()) | ||
} | ||
|
||
@Override | ||
boolean supports(ApplicationType applicationType) { | ||
true | ||
} | ||
} | ||
} |