Getting contents and natures of all projects in a Maven build - api

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?

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.

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.

Related

How to put Maven Tycho Dependency in my Eclipse Plug-in?

I've created a new project using tycho 0.26.0, it runs with Eclipse 4 Neon.2, so all modules are building successfully using maven, now I am trying to add a new dependency in my project, I have created a jar and I want to use it in my project, but I don't understand so good how is it working.
I add I am using a target definition, so I have to add my configuration to this file, this will be used by my modules.
I don't know if I got your question right.
I assume you want to build an Eclipse RCP application with tycho and use an JAR file from one of your plug-ins.
The simplest solution is then to create a new plug-in project from this jar by using the Plug-in from existing JAR Archives-Wizard.
If you have done this, you can add a dependency from this new plug-in to your existing plug-ins. Don't forget to export all packages of the library, by opening Manifest.mf and adding all packages in the Runtime tab.
To get this running with maven you have also to add a pom.xml file to the new Plug-in. This link help me a lot with maven tycho (http://codeandme.blogspot.de/p/tycho-articles.html).
Btw. if you don't need this library as plain JAR, you can also create directly a Plug-in project instead of first creating a JAR and then creating a Plug-in project.

IntelliJ IDEA with multiple gradle subprojects

I'm working on multiple Gradle projects with internal and external dependencies, and so far I am happy that thanks to Gradle's dependency management I can modify a library project without affecting every application that uses the library.
When I need to modify a library project and test it using an application project that uses it, I need to do the following,
Modify the library project and commit to SCM
Trigger CI to build the library project and push it to my Gradle repository
Update the application project's build.properties to refer to the new version of library project
Iterate the above steps until everything works and there is no bug
So it became quite combersome now. Can I configure IntelliJ IDEA so that
All my Gradle projects are in one window, like the screenshot below, which is Twitter's Finagle imported using its pom.xml. Sadly IntelliJ's JetGradle plugin doesn't seem to understand Gradle subprojects.
When build.properties's dependencies are my subprojects, read dependency from local snapshot, otherwise download them from the Gradle repository
Thanks.
If you want to open all projects in a single IDEA window, you'll have to aggregate them into a multi-project build, at least until IDEA 13 hits the market. Before IDEA 13, it's better to use Gradle's IDEA integration. Once you have a multi-project build, all you need to do is to add allprojects { apply plugin: "idea" } to the root build script, run gradle (cleanIdea) idea, then open the generated IDEA project.
Currently in IntelliJ IDEA 2019.2 you can add the gradle subprojects like so
Open Gradle Tool Window via View > Tool Windows > Gradle menu
Click on "Link Gradle Project" button (the plus sign)
Select the build.gradle file corresponding to the subproject
Go to File > Project Structure > Modules > NameOfSubproject
Navigate to main/java and click on Mark as: Sources
Mark the main/resources as Resources
Restart IntelliJ IDEA
The sources of the subproject will be recognized by IntelliJ and you can use Navigate Class action for the classes in the subproject

Maven2_Builder vs. Maven Project Builder

I inherited a project that relies on Maven 2 to build it. Via project's Properties > Builders I can see that it has two builders, in this order:
Maven2_Builder
Maven Project Builder
I thought that there should be only one Maven builder...
Why two?
What the relation between the two?
Using the m2e plugin, I can clean the project at any given time via the project's context menu Run As > 6 Maven Clean. Does this mean Eclipse's Project > Clean... is no longer relevant?
Looks like you are using Eclipse with M2E. These days that works very well.
Before one would run
mvn eclipse:eclipse
Which would generate the typical Eclipse configuration files.
These days, just use the Eclipse Import as Maven Project and all necessary files are created.

Binary output and testing for Eclipse plugins

I am developing an Eclipse plugin and I use maven to coordinate my source structure. In order to compile the plugin I use the tycho extension for maven. However, I was wondering how to execute unitests.
I want to use the surefire plugin for testing as I additionally use a sonar server for source code quality management. Unitests are applyed if I use eclipse-test-plugin as package target. However, I want to make use of the default surefire plugin for applying unitests.
Now I figured out that the src/test/java that contains my unittest packages is read and compiled correctly but written into the wrong output folder. I need to have the tests in target/test-classes. However they are compiled to target/classes.
As I am new to Eclipse plugin development and maven I could not find out how to write the tests to the correct output folder. I've already tried adding and and changing the build.properties of the eclipse-plugin project. It works also fine for other projects that aren't plugin projects and do not make use of tycho.
Any help appreciated.
Regards,
Florian
Unlike standard maven projects, the convention for eclipse plugins/OSGi bundles is to have tests reside in separate projects. This is because there is no such thing as a maven dependency scope "test" in OSGi.
Thus keeping your tests inside the same project as your code under test would force you to mix up test code/dependencies an productive code/dependencies.
As you mentioned, Tycho provides a separate maven packaging type "eclipse-test-plugin" which you should use for dedicated test plugins/fragments. See https://docs.sonatype.org/display/TYCHO/PackagingTypes
There is no support in Tycho for plain unit tests residing in the same project.

Link Maven OSGi to Maven NetBeans Platform Project

I am using NetBeans 6.9 Beta and I would like to accomplish the following:
Set up a project representing the main application using Maven (for instance "Maven Project", "Maven NetBeans Application")
Ideally, the project should only contain the necessary libraries to run in Apache Felix (I would like to be able to right-click the project and select "Run in Felix")
I do not want that the project contains all the NetBean Platform APIs
I would prefer to implement the modules using OSGi. For instance "Maven OSGi Bundle", "Maven NetBeans Module" + OSGi
These are the problems, which I have at the moment:
The standard Maven archetype ("Maven NetBeans Application") seems always to select all APIs and I have not found a way to deselect APIs - in normal NetBeans Platform Applications that can be accomplished by going to the project properties and deselected the platform modules) - I guess it has something to do with the NetBeans repository (http://bits.netbeans.org/maven2)? Do I have to create another repository?
When creating normal "NetBeans Module" with OSGi support, the modules contain both NetBeans Module and OSGi meta data, which is nice. So, for instance the tool support in NetBeans is available for both technologies. But the "Maven NetBeans Modules" have only NetBeans meta data and the Maven OSGi Bundles have only OSGi meta data).
3. I figured out how to add modules to the project by using project / new and then placing the modules in the Maven project folder. However, I do not quite know yet how I could link to modules from other locations (NetBeans uses Maven modules, which have to be in the same directory as the project?).
Below some useful links for Maven + OSGi in NetBeans
wiki.netbeans.org/STS_69_Maven_OSGI NetBeans Maven OSGi Test Specification
platform.netbeans.org/tutorials/nbm-maven-quickstart.html NetBeans Platform Quick Start Using Maven (6.9)
wiki.netbeans.org/MavenBestPractices NetBeans Maven BestPractices
maven.apache.org/pom.html#Aggregation Maven Documentation Multi-Module Projects
(sorry about the missing protocol but couldn't post the message otherwise)
your nbm-application project depends on all platform projects.. just use the regular maven dependency management (adding/removing dependencies, adding dependency excludes to limit your platform
configure the nbm plugin and the bundle plugin yourself to sequentially append content to the manifest file.. I think Fabrizio Guidici's forceten and bluemarine projects do that in some way..
I don't understand the problem entirely. maven modules are a different thing than netbeans modules. you can for sure compose the application from multiple independently build nb module artifacts.