Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use platform architecture in Maven to determine dependency?

As the question states is there a nice way to use dependencies based on the platform architecture while building maven artefacts. I know about profiles and how to use them. For this special purpose i dont want to incorporate them into my build.

The problem in detail could be described as follows:

  • Multi module maven project
  • Continous integration and people on the project use evenly distributed platform architectures
  • Dependency to native system library

Solutions which i do not want to use in the settings:

  • No dependency redundancy
  • No maven profiles (or at least maven profiles which are automatically chosen by platform architecture)

As an example:

Person1

  • (using linux i686) builds project
  • x86 libaries are bundled to every subproject and the resulting artefacts are being build

Person2

  • (using win32) builds project
  • 32 bit librariers are bundled as above

Continous integration

  • is running like the production environment on linux amd64
  • integrate amd64 libraries

Edit about Profiles

I know that profiles are one solution to do this. But what i want to achieve is that you checkout your project from some random source version control and build a project with native libraries out of the box without doing anything (as long as the platform meets the requirement of the configured ones).

I do not want to configure these profile settings nor i want to run a specific target explicitally. If there is such thing with profiles i would like to see an example which determines automatically the platform architecture and runs a target. IF there is one without profiles i would prefer it because it is much less complex while having different existent combinations of profiles(including tests and other usecases).

Having solely profiles feels a little bloated to me and manual efforts are required.

I hope someone has a neat suggestion because im somehow stuck on this.

like image 602
fyr Avatar asked Jul 20 '11 12:07

fyr


People also ask

How do you determine dependency hierarchy?

Maven Dependency Tree in Eclipse IDEEclipse pom. xml “Dependency Hierarchy” tab shows the dependency tree of the project. It has two sides - the left side shows verbose output and the right side shows the resolved dependencies. We can use the “Filter” option to look for a specific dependency.

Where can I find dependencies in Maven?

In your project's POM, press Ctrl and hover the mouse over the dependency. Click the dependency to open the dependency's POM. In the dependency POM, view the active dependency, its transitive dependencies and their versions. You can check the origin from which the dependency was pulled in.

How does Maven work with dependencies?

Maven includes a dependency with this scope in the runtime and test classpaths, but not the compile classpath. This scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases. This scope is not transitive.

How do I run a dependency in Maven?

Add a Java Maven Dependency to the Utility ProjectRight-click the utility project, and select Maven>Add Dependency. Type a dependency name in the Enter groupID… field (e.g., commons-logging) to search for a dependency. Select the dependency, and click OK.


1 Answers

I don't know of any way to do this without profiles. This is the main use case for which profiles were added to maven. You can do it using the following:

<profiles>
  <profile>
    <activation>
      <os>
        <name>Windows XP</name>
        <family>Windows</family>
        <arch>x86</arch>
      </os>
    </activation>
    ...
  </profile>
  <profile>
    <activation>
      <os>
        <family>Linux</family>
        <arch>x64</arch>
      </os>
    </activation>
    ...
  </profile>
  <profile>
    <activation>
      <property>
         <name>integration-test</name>
      </property>
    </activation>
    ...
  </profile>
</profiles>

Then, when someone checks out a project and builds it on a Linux x64 machine, they will automatically get everything under the Linux x64 profile. If they also provided the property -Dintegration-test on the command line, they would activate the integration-test profile as well. You can have any number of active profiles, which are combined to create the effective POM for the build. These profiles can be defined in a shared parent POM for all projects that you work on, so developers don't have to change their settings.xml files.

To get more info on the activation of profiles, check out: http://maven.apache.org/guides/introduction/introduction-to-profiles.html.

like image 57
Ryan Gross Avatar answered Sep 21 '22 02:09

Ryan Gross