@@ -1787,25 +1787,47 @@ private void writeDebugFile(
1787
1787
try (BufferedWriter out = Files .newBufferedWriter (path )) {
1788
1788
compilerConfiguration .format (commandLine , out );
1789
1789
for (Map .Entry <PathType , List <Path >> entry : dependencies .entrySet ()) {
1790
+ List <Path > files = entry .getValue ();
1791
+ files = files .stream ().map (this ::relativize ).toList ();
1790
1792
String separator = "" ;
1791
- for (String element : entry .getKey ().option (entry . getValue () )) {
1793
+ for (String element : entry .getKey ().option (files )) {
1792
1794
out .write (separator );
1793
1795
out .write (element );
1794
1796
separator = " " ;
1795
1797
}
1796
1798
out .newLine ();
1797
1799
}
1798
1800
out .write ("-d \" " );
1799
- out .write (getOutputDirectory ().toString ());
1801
+ out .write (relativize ( getOutputDirectory () ).toString ());
1800
1802
out .write ('"' );
1801
1803
out .newLine ();
1802
1804
for (SourceFile sf : sourceFiles ) {
1803
1805
out .write ('"' );
1804
- out .write (sf .file .toString ());
1806
+ out .write (relativize ( sf .file ) .toString ());
1805
1807
out .write ('"' );
1806
1808
out .newLine ();
1807
1809
}
1808
1810
}
1809
1811
tipForCommandLineCompilation = commandLine .append (" @" ).append (path ).toString ();
1810
1812
}
1813
+
1814
+ /**
1815
+ * Makes the given file relative to the base directory if the path is inside the project directory tree.
1816
+ * The check for the project directory tree (starting from the root of all sub-projects) is for avoiding
1817
+ * to relativize the paths to JAR files in the Maven local repository for example.
1818
+ *
1819
+ * @param file the path to make relative to the base directory
1820
+ * @return the given path, potentially relative to the base directory
1821
+ */
1822
+ private Path relativize (Path file ) {
1823
+ Path root = project .getRootDirectory ();
1824
+ if (root != null && file .startsWith (root )) {
1825
+ try {
1826
+ file = basedir .relativize (file );
1827
+ } catch (IllegalArgumentException e ) {
1828
+ // Ignore, keep the absolute path.
1829
+ }
1830
+ }
1831
+ return file ;
1832
+ }
1811
1833
}
0 commit comments