On 5 September 2016 at 12:11, Christopher wrote:
> Hi,
>
> I'm trying to write a Maven plugin which gets, and processes, a list of
> classes from the project. I want to be able to get the project classes
> compiled from either src/main/java (compile scope), and src/test/java (test
> scope, minus compile scope), depending on user configuration.
>
> So far, the closest things I've found to help me are (project is an
> instance of MavenProject):
> project.getCompileClasspathElements()
> and
> project.getTestClasspathElements()
>
> I then use that to build a URLClassLoader, which I then use Guava's
> ClassPath utility to find all the classes.
>
> The problem is, that brings in the whole classpath, and all I want is just
> the project's own classes, not those from dependencies (including Java
> itself). And, the test classpath elements includes the compile-time scoped
> items, as well, which I don't necessarily want. I could probably do set
> subtraction to remove the compile-time scope from the test scope, but I
> can't figure out how to get rid of what's being added as dependencies,
> which I don't wish to process. Perhaps I can do set subtraction from the
> dependencies? Is there a way to enumerate the classpath of just the
> dependencies?
>
> Has anybody done anything like this? Is there a better way to get only the
> project's own classes?
>
Why are you wanting to do this?
Are the output files in target/classes and target/test-classes not
sufficient?