@@ -1787,25 +1787,46 @@ private void writeDebugFile(
17871787 try (BufferedWriter out = Files .newBufferedWriter (path )) {
17881788 compilerConfiguration .format (commandLine , out );
17891789 for (Map .Entry <PathType , List <Path >> entry : dependencies .entrySet ()) {
1790+ List <Path > files = entry .getValue ();
1791+ files = files .stream ().map (this ::relativize ).toList ();
17901792 String separator = "" ;
1791- for (String element : entry .getKey ().option (entry . getValue () )) {
1793+ for (String element : entry .getKey ().option (files )) {
17921794 out .write (separator );
17931795 out .write (element );
17941796 separator = " " ;
17951797 }
17961798 out .newLine ();
17971799 }
17981800 out .write ("-d \" " );
1799- out .write (getOutputDirectory ().toString ());
1801+ out .write (relativize ( getOutputDirectory () ).toString ());
18001802 out .write ('"' );
18011803 out .newLine ();
18021804 for (SourceFile sf : sourceFiles ) {
18031805 out .write ('"' );
1804- out .write (sf .file .toString ());
1806+ out .write (relativize ( sf .file ) .toString ());
18051807 out .write ('"' );
18061808 out .newLine ();
18071809 }
18081810 }
18091811 tipForCommandLineCompilation = commandLine .append (" @" ).append (path ).toString ();
18101812 }
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+ if (file .startsWith (project .getRootDirectory ())) {
1824+ try {
1825+ file = basedir .relativize (file );
1826+ } catch (IllegalArgumentException e ) {
1827+ // Ignore, keep the absolute path.
1828+ }
1829+ }
1830+ return file ;
1831+ }
18111832}
0 commit comments