0

Currently I'm working on a Maven plugin that should generate files in all projects (OSGi bundles) that have a certain Eclipse project nature.

How can I access the contents of the projects included in the build and the project natures by using the Maven API?

user1056903
  • 921
  • 9
  • 26

2 Answers2

0

Maven is a standalone build tool, not an Eclipse plugin. You cannot access Eclipse project settings from core Maven API.

Eclipse supports Maven with the M2E Eclipse plugin. It is possible to write M2E extensions and in the extension you can query the project natures via the functions of AbstractProjectConfigurator class.

However, M2E extensions will not run when you compile your code in the command line. I suggest that you choose one of the followings:

  • Write an Eclipse plugin that generates the source code into the src folder of the maven project. Code generation should be started by the user manually (selecting a context menu in the project or something).
  • Avoid using Eclipse project natures and solve your questions based on analyzing the source and pom of your project.
Balazs Zsoldos
  • 6,036
  • 2
  • 23
  • 31
  • How can I access the sources of all projects that are built? – user1056903 Sep 03 '14 at 12:23
  • By simply writing a simple M2E excension, I do not think you can. You must write an Eclipse plugin for that. Are you sure you cannot check anything else but the project natures? What about writing a maven plugin that generates code based on the configuration of the plugin? – Balazs Zsoldos Sep 03 '14 at 12:32
  • I could alternatively check for a file that must be in the root of the project. If this file exist, the files should be generatd in the project. Is there no way to access the contents of the projects during the build? – user1056903 Sep 03 '14 at 13:26
  • If you do a command line build, it does not know about Eclipse at all. The goal of maven is to keep every configuration in the pom file. Developer tools like Eclipse should get the information from the pom (e.g.: Add a facet to the project). So it is the other way normally as you want to solve the problem. – Balazs Zsoldos Sep 03 '14 at 14:26
0

If you need to react on certain aspects in the source code like it looks from the thread with Balazs then you can simply write an ordinary maven plugin and include it in the parent pom. It will then run in every project and can analyze the code and react based on it.

Christian Schneider
  • 19,420
  • 2
  • 39
  • 64