@@ -110,18 +110,34 @@ private FileObject createMetadataResource() throws IOException {
110
110
111
111
private InputStream getAdditionalMetadataStream () throws IOException {
112
112
// Most build systems will have copied the file to the class output location
113
- FileObject fileObject = this .environment .getFiler ()
114
- . getResource ( StandardLocation . CLASS_OUTPUT , "" , ADDITIONAL_METADATA_PATH );
113
+ FileObject fileObject = this .environment .getFiler (). getResource ( StandardLocation . CLASS_OUTPUT , "" , ADDITIONAL_METADATA_PATH );
114
+
115
115
File file = new File (fileObject .toUri ());
116
+
116
117
if (!file .exists ()) {
117
118
// Gradle keeps things separate
118
119
String path = file .getPath ();
120
+
119
121
int index = path .lastIndexOf (CLASSES_FOLDER );
120
122
if (index >= 0 ) {
121
- path = path .substring (0 , index ) + RESOURCES_FOLDER
122
- + path .substring (index + CLASSES_FOLDER .length ());
123
- file = new File (path );
123
+ /*
124
+ Gradle 4 introduces a new 'java' directory which causes issues for one-to-one path mapping
125
+ of class locations and resources. Ensure resources can be found under '/build/resources/main'
126
+ rather than '/build/resources/java/main'.
127
+ */
128
+ final String pathBeforeClassFolder = path .substring (0 , index );
129
+ /*
130
+ In order to retrieve the the class output resource, we MUST pass in a relative path.
131
+ An empty path causes a InvalidArgumentException as it must be resolvable. In reality,
132
+ this means nothing since we are going to traverse upstream to its parent to locate
133
+ the 'main' directory.
134
+ */
135
+ FileObject classOutputLocation = this .environment .getFiler ().getResource (StandardLocation .CLASS_OUTPUT , "" , "dummy" );
136
+ File classesFolder = new File (classOutputLocation .toUri ());
137
+ File resourcesFolder = new File (pathBeforeClassFolder + RESOURCES_FOLDER + '/' + classesFolder .getParentFile ().getName ());
138
+ file = new File (resourcesFolder , ADDITIONAL_METADATA_PATH );
124
139
}
140
+
125
141
}
126
142
return (file .exists () ? new FileInputStream (file )
127
143
: fileObject .toUri ().toURL ().openStream ());
0 commit comments