Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.core.IClasspathAttribute;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.search.IJavaSearchConstants;
Expand All @@ -36,6 +38,7 @@

public class ResolveClasspathsHandler {
private static final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME);
private static final String SCOPE_ATTRIBUTE = "maven.scope";

/**
* Resolves class path for a java project.
Expand Down Expand Up @@ -178,10 +181,10 @@ private static String[] computeDefaultRuntimeClassPath(IJavaProject jproject) th
for (int i = 0; i < unresolved.length; i++) {
IRuntimeClasspathEntry entry = unresolved[i];
if (entry.getClasspathProperty() == IRuntimeClasspathEntry.USER_CLASSES) {
IRuntimeClasspathEntry[] entries = JavaRuntime.resolveRuntimeClasspathEntry(entry, jproject);
IRuntimeClasspathEntry[] entries = JavaRuntime.resolveRuntimeClasspathEntry(entry, jproject, true);
for (int j = 0; j < entries.length; j++) {

if (entries[j].getClasspathEntry().isTest()) {
if (entries[j].getClasspathEntry().isTest() && !isRuntime(entries[j].getClasspathEntry())) {
Copy link
Collaborator

@fbricon fbricon Sep 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you should always add runtime classes, regardless of their "test" attribute
it's fine

continue;
}
String location = entries[j].getLocation();
Expand All @@ -193,4 +196,13 @@ private static String[] computeDefaultRuntimeClassPath(IJavaProject jproject) th
}
return resolved.toArray(new String[resolved.size()]);
}

private static boolean isRuntime(final IClasspathEntry classpathEntry) {
for (IClasspathAttribute attribute : classpathEntry.getExtraAttributes()) {
if (SCOPE_ATTRIBUTE.equals(attribute.getName()) && "runtime".equals(attribute.getValue())) {
return true;
}
}
return false;
}
}