Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Maven/Groovy builds with zipkin and jaeger #2483

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2022 original authors
* Copyright 2017-2024 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,6 +31,7 @@ public final class MicronautDependencyUtils {
public static final String GROUP_ID_MICRONAUT_TESTRESOURCES = "io.micronaut.testresources";
public static final String GROUP_ID_MICRONAUT_JAXRS = "io.micronaut.jaxrs";
public static final String GROUP_ID_MICRONAUT_MICROSTREAM = "io.micronaut.microstream";
public static final String ARTIFACT_ID_MICRONAUT_CORE_PROCESSOR = "micronaut-core-processor";
public static final String ARTIFACT_ID_MICRONAUT_INJECT_JAVA = "micronaut-inject-java";
public static final String GROUP_ID_MICRONAUT_AWS = "io.micronaut.aws";
public static final String GROUP_ID_MICRONAUT_AZURE = "io.micronaut.azure";
Expand Down Expand Up @@ -259,6 +260,11 @@ public static Dependency.Builder injectJava() {
return coreDependency().artifactId(ARTIFACT_ID_MICRONAUT_INJECT_JAVA);
}

@NonNull
public static Dependency.Builder coreProcessor() {
return coreDependency().artifactId(ARTIFACT_ID_MICRONAUT_CORE_PROCESSOR);
}

@NonNull
public static Dependency.Builder picocliDependency() {
return micronautDependency(GROUP_ID_IO_MICRONAUT_PICOCLI);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2022 original authors
* Copyright 2017-2024 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,18 +17,22 @@

import io.micronaut.core.annotation.NonNull;
import io.micronaut.starter.application.generator.GeneratorContext;
import io.micronaut.starter.build.dependencies.Dependency;
import io.micronaut.starter.build.dependencies.MicronautDependencyUtils;
import io.micronaut.starter.feature.server.MicronautServerDependent;

import io.micronaut.starter.options.BuildTool;
import io.micronaut.starter.options.Language;
import jakarta.inject.Singleton;

@Singleton
public class Jaeger implements TracingFeature, MicronautServerDependent {

public static final String NAME = "tracing-jaeger";

@NonNull
@Override
public String getName() {
return "tracing-jaeger";
return NAME;
}

@Override
Expand All @@ -47,10 +51,13 @@ public void apply(GeneratorContext generatorContext) {
generatorContext.getConfiguration().put("tracing.jaeger.enabled", true);
generatorContext.getConfiguration().put("tracing.jaeger.sampler.probability", 0.1);

generatorContext.addDependency(Dependency.builder()
.groupId("io.micronaut.tracing")
generatorContext.addDependency(MicronautDependencyUtils.tracingDependency()
.artifactId("micronaut-tracing-jaeger")
.compile());

if (generatorContext.getBuildTool() == BuildTool.MAVEN && generatorContext.getLanguage() == Language.GROOVY) {
generatorContext.addDependency(MicronautDependencyUtils.coreProcessor().compileOnly());
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2022 original authors
* Copyright 2017-2024 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,17 +20,20 @@
import io.micronaut.starter.build.dependencies.MicronautDependencyUtils;
import io.micronaut.starter.feature.server.MicronautServerDependent;

import io.micronaut.starter.options.BuildTool;
import io.micronaut.starter.options.Language;
import jakarta.inject.Singleton;

@Singleton
public class Zipkin implements TracingFeature, MicronautServerDependent {

public static final String NAME = "tracing-zipkin";
private static final String ARTIFACT_ID_MICRONAUT_TRACING_BRAVE_HTTP = "micronaut-tracing-brave-http";

@NonNull
@Override
public String getName() {
return "tracing-zipkin";
return NAME;
}

@Override
Expand All @@ -56,6 +59,10 @@ protected void addDependencies(GeneratorContext generatorContext) {
generatorContext.addDependency(MicronautDependencyUtils.tracingDependency()
.artifactId(ARTIFACT_ID_MICRONAUT_TRACING_BRAVE_HTTP)
.compile());

if (generatorContext.getBuildTool() == BuildTool.MAVEN && generatorContext.getLanguage() == Language.GROOVY) {
generatorContext.addDependency(MicronautDependencyUtils.coreProcessor().compileOnly());
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class JaegerSpec extends ApplicationContextSpec implements CommandOutputFixture

void 'test readme.md with feature tracing-jaeger contains links to micronaut docs'() {
when:
Map output = generate(['tracing-jaeger'])
Map output = generate([Jaeger.NAME])
String readme = output['README.md']

then:
Expand All @@ -28,7 +28,7 @@ class JaegerSpec extends ApplicationContextSpec implements CommandOutputFixture
when:
String template = new BuildBuilder(beanContext, GRADLE)
.language(language)
.features(['tracing-jaeger'])
.features([Jaeger.NAME])
.render()

then:
Expand All @@ -43,7 +43,7 @@ class JaegerSpec extends ApplicationContextSpec implements CommandOutputFixture
when:
String template = new BuildBuilder(beanContext, MAVEN)
.language(language)
.features(['tracing-jaeger'])
.features([Jaeger.NAME])
.render()

then:
Expand All @@ -61,7 +61,7 @@ class JaegerSpec extends ApplicationContextSpec implements CommandOutputFixture

void 'test tracing-jaeger configuration'() {
when:
GeneratorContext commandContext = buildGeneratorContext(['tracing-jaeger'])
GeneratorContext commandContext = buildGeneratorContext([Jaeger.NAME])

then:
commandContext.configuration.get('tracing.jaeger.enabled') == true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ZipkinSpec extends ApplicationContextSpec implements CommandOutputFixture

void 'test readme.md with feature tracing-zipkin contains links to micronaut docs'() {
when:
Map output = generate(['tracing-zipkin'])
Map output = generate([Zipkin.NAME])
String readme = output['README.md']

then:
Expand All @@ -27,7 +27,7 @@ class ZipkinSpec extends ApplicationContextSpec implements CommandOutputFixture
@Unroll
void 'test gradle tracing-zipkin feature for language=#language'(Language language, BuildTool buildTool) {
given:
String feature = 'tracing-zipkin'
String feature = Zipkin.NAME
when:
String template = new BuildBuilder(beanContext, buildTool)
.features([feature])
Expand All @@ -44,7 +44,7 @@ class ZipkinSpec extends ApplicationContextSpec implements CommandOutputFixture

void 'test tracing-zipkin configuration'() {
when:
GeneratorContext commandContext = buildGeneratorContext(['tracing-zipkin'])
GeneratorContext commandContext = buildGeneratorContext([Zipkin.NAME])

then:
commandContext.configuration.get('tracing.zipkin.enabled') == true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.micronaut.starter.core.test.feature.tracing

import io.micronaut.starter.feature.tracing.Jaeger
import io.micronaut.starter.options.BuildTool
import io.micronaut.starter.options.Language
import io.micronaut.starter.test.CommandSpec
import io.micronaut.starter.test.LanguageBuildCombinations

class JaegerSpec extends CommandSpec {

void 'test jaeger feature for #lang and #buildTool'(Language lang, BuildTool buildTool) {
given:
generateProject(lang, buildTool, [Jaeger.NAME])

when:
String output = executeBuild(buildTool, "test")

then:
output.contains("BUILD SUCCESS")

where:
[lang, buildTool] << LanguageBuildCombinations.combinations()
}

@Override
String getTempDirectoryPrefix() {
return "jaeger-tracing-app"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.micronaut.starter.core.test.feature.tracing

import io.micronaut.starter.feature.tracing.Zipkin
import io.micronaut.starter.options.BuildTool
import io.micronaut.starter.options.Language
import io.micronaut.starter.test.CommandSpec
import io.micronaut.starter.test.LanguageBuildCombinations

class ZipkinSpec extends CommandSpec {

void 'test zipkin feature for #lang and #buildTool'(Language lang, BuildTool buildTool) {
given:
println dir
generateProject(lang, buildTool, [Zipkin.NAME])

when:
String output = executeBuild(buildTool, "test")

then:
output.contains("BUILD SUCCESS")

where:
[lang, buildTool] << LanguageBuildCombinations.combinations()
}

@Override
String getTempDirectoryPrefix() {
return "zipkin-tracing-app"
}
}
Loading