Make discovery of additional config metdata more robust with Gradle
Previously, the configuration metadata annotation processor relied upon an additional metadata file have been copied to an output location. When building with Gradle, it's the processResources task that performs this copy and there is no guarantee that it will have run before the compileJava task unless an explicit dependency betwee the two tasks has been configured. If a project is built using Gradle's parallel build support, the likelihood of this required ordering not occurring increases. This commit updates the configuration metadata annotation processor to consider a new annotation processor option when looking for the additional config metadata file. The Gradle plugin has been updated to provide this option as a compiler argument. The option is only provided when the annotation processor is found on the compilation classpath to avoid a warning from javac's annotation processing about the use of an option that is not supported by any of the available annotation processors. Closes gh-9755
This commit is contained in:
@@ -18,6 +18,7 @@ package org.springframework.boot.configurationprocessor;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
import javax.annotation.processing.ProcessingEnvironment;
|
||||
|
||||
@@ -26,6 +27,7 @@ import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -38,8 +40,9 @@ public class MetadataStoreTests {
|
||||
@Rule
|
||||
public final TemporaryFolder temp = new TemporaryFolder();
|
||||
|
||||
private final MetadataStore metadataStore = new MetadataStore(
|
||||
mock(ProcessingEnvironment.class));
|
||||
private final ProcessingEnvironment environment = mock(ProcessingEnvironment.class);
|
||||
|
||||
private final MetadataStore metadataStore = new MetadataStore(this.environment);
|
||||
|
||||
@Test
|
||||
public void additionalMetadataIsLocatedInMavenBuild() throws IOException {
|
||||
@@ -88,4 +91,20 @@ public class MetadataStoreTests {
|
||||
.isEqualTo(additionalMetadata);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void additionalMetadataIsLocatedUsingLocationsOption() throws IOException {
|
||||
File app = this.temp.newFolder("app");
|
||||
File location = new File(app, "src/main/resources");
|
||||
File metaInf = new File(location, "META-INF");
|
||||
metaInf.mkdirs();
|
||||
File additionalMetadata = new File(metaInf,
|
||||
"additional-spring-configuration-metadata.json");
|
||||
additionalMetadata.createNewFile();
|
||||
given(this.environment.getOptions()).willReturn(Collections.singletonMap(
|
||||
ConfigurationMetadataAnnotationProcessor.ADDITIONAL_METADATA_LOCATIONS_OPTION,
|
||||
location.getAbsolutePath()));
|
||||
assertThat(this.metadataStore.locateAdditionalMetadataFile(new File(app, "foo")))
|
||||
.isEqualTo(additionalMetadata);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user