@@ -238,6 +238,7 @@ private List<File> getJars(List<File> files) {
238238 @ Override
239239 public void configureClasspath (IClasspathDescriptor classpath , IProgressMonitor monitor ) throws CoreException {
240240
241+ removeStaled (classpath );
241242 AnnotationProcessorConfiguration configuration = getAnnotationProcessorConfiguration (monitor );
242243
243244 if ((configuration == null ) || !configuration .isAnnotationProcessingEnabled ()) {
@@ -259,6 +260,10 @@ public void configureClasspath(IClasspathDescriptor classpath, IProgressMonitor
259260 File outputFolder = new File (mavenProject .getBuild ().getTestOutputDirectory ());
260261 addToClassPath (eclipseProject , generatedTestSourcesDirectory , outputFolder , classpath , true );
261262 }
263+ if (generatedSourcesDirectory != null || generatedTestSourcesDirectory != null ) {
264+ IJavaProject javaProject = JavaCore .create (eclipseProject );
265+ javaProject .setRawClasspath (classpath .getEntries (), monitor );
266+ }
262267 }
263268
264269 protected abstract AnnotationProcessorConfiguration getAnnotationProcessorConfiguration (IProgressMonitor monitor )
@@ -283,11 +288,9 @@ private void addToClassPath(IProject project, File sourceDirectory, File targetD
283288 IPath [] includes = new IPath [] {};
284289 IPath [] excludes = new IPath [] {};
285290
286- // If the source folder is non-nested , add it
291+ // If the source folder doesn't exist , add it
287292 if ((generatedSourcesFolder != null ) && generatedSourcesFolder .getProject ().equals (project )) {
288- IClasspathEntryDescriptor enclosing = getEnclosingEntryDescriptor (classpath ,
289- generatedSourcesFolder .getFullPath ());
290- if ((enclosing == null ) || (getEntryDescriptor (classpath , generatedSourcesFolder .getFullPath ()) != null )) {
293+ if (getEntryDescriptor (classpath , generatedSourcesFolder .getFullPath ()) == null ) {
291294 IClasspathEntryDescriptor entry = classpath .addSourceEntry (generatedSourcesFolder .getFullPath (), outputPath ,
292295 includes , excludes , true );
293296 entry .setClasspathAttribute (IClasspathAttribute .IGNORE_OPTIONAL_PROBLEMS , "true" ); //$NON-NLS-1$
@@ -331,20 +334,25 @@ private static IClasspathEntryDescriptor getEnclosingEntryDescriptor(IClasspathD
331334 return null ;
332335 }
333336
334- private IClasspathEntryDescriptor getEntryDescriptor (IClasspathDescriptor classpath , IPath fullPath ) {
337+ private void removeStaled (IClasspathDescriptor classpath ) {
335338 List <IPath > stalePaths = new ArrayList <>();
336- IClasspathEntryDescriptor matchingDescriptor = null ;
337339 for (IClasspathEntryDescriptor cped : classpath .getEntryDescriptors ()) {
338- if (cped .getPath ().equals (fullPath )) {
339- matchingDescriptor = cped ;
340- } else if (Boolean .parseBoolean (cped .getClasspathAttributes ().get (M2E_APT_KEY ))) {
340+ if (Boolean .parseBoolean (cped .getClasspathAttributes ().get (M2E_APT_KEY ))) {
341341 stalePaths .add (cped .getPath ());
342342 }
343343 }
344344 for (IPath stalePath : stalePaths ) {
345345 classpath .removeEntry (stalePath );
346346 }
347- return matchingDescriptor ;
347+ }
348+
349+ private IClasspathEntryDescriptor getEntryDescriptor (IClasspathDescriptor classpath , IPath fullPath ) {
350+ for (IClasspathEntryDescriptor cped : classpath .getEntryDescriptors ()) {
351+ if (cped .getPath ().equals (fullPath )) {
352+ return cped ;
353+ }
354+ }
355+ return null ;
348356 }
349357
350358 protected <T > T getParameterValue (String parameter , Class <T > asType , MojoExecution mojoExecution )
0 commit comments