GH-160 - Prevent missing ArchUnit runtime dependency.

Adds ArchUnit as an explicit dependency to spring-modulith-runtime. Registers auto-configuration that throws an exception in case ArchUnit is missing from the classpath (as it is likely that it's declared as test scope dependency only) and a corresponding failure analyzer to give guidance on how to solve the problem.
This commit is contained in:
Michael Weirauch
2023-03-06 23:38:22 +01:00
committed by Oliver Drotbohm
parent e16efe92d2
commit 595a052702
6 changed files with 116 additions and 0 deletions

View File

@@ -18,16 +18,21 @@ package org.springframework.modulith.runtime.autoconfigure;
import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.springframework.beans.BeanInstantiationException;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.FilteredClassLoader;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.modulith.runtime.ApplicationModulesRuntime;
import org.springframework.modulith.runtime.ApplicationRuntime;
import com.tngtech.archunit.core.importer.ClassFileImporter;
/**
* Integration test for {@link SpringModulithRuntimeAutoConfiguration}.
*
* @author Oliver Drotbohm
* @author Michael Weirauch
*/
class SpringModulithRuntimeAutoConfigurationIntegrationTests {
@@ -48,4 +53,22 @@ class SpringModulithRuntimeAutoConfigurationIntegrationTests {
context.close();
});
}
@Test
void missingArchUnitRuntimeDependencyEscalatesOnContextStartup() {
new ApplicationContextRunner()
.withUserConfiguration(SampleApp.class)
.withConfiguration(AutoConfigurations.of(SpringModulithRuntimeAutoConfiguration.class))
.withClassLoader(new FilteredClassLoader(ClassFileImporter.class))
.run(context -> {
assertThat(context).hasFailed();
assertThat(context.getStartupFailure().getCause())
.isInstanceOf(BeanInstantiationException.class)
.cause().isInstanceOf(MissingRuntimeDependencyException.class);
context.close();
});
}
}