Maven Runtime can introspect a class loader to obtain metadata for each Maven project accessible within it.
To obtain a list of MavenProjectProperties instances for each Maven project accessible within a specified class loader:
/** * @component */ private MavenRuntime runtime; public void processProjects() throws MavenRuntimeException { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); List<MavenProjectProperties> projects = runtime.getProjectsProperties( classLoader ); // process projects }
To obtain a list of MavenProject instances for each Maven project accessible within a specified class loader:
/** * @component */ private MavenRuntime runtime; public void processProjects() throws MavenRuntimeException { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); List<MavenProject> projects = runtime.getProjects( classLoader ); // process projects }
When obtaining Maven metadata using project XML, the resultant MavenProject instances can be sorted by dependency order. To obtain a list of MavenProject instances for each Maven project accessible within a specified class loader ordered by their dependencies:
/** * @component */ private MavenRuntime runtime; public void processProjects() throws MavenRuntimeException { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); List<MavenProject> projects = runtime.getSortedProjects( classLoader ); // process projects }
Note that project properties cannot be sorted by dependency order since they do not contain any dependency information.