33463

How to get properties of parent Maven to Gradle

Question:

We have multiple projects which use maven as build automation tool these project are developed and used by multiple teams in our company. We have a parent application in which we have the generic plugin related code, we use as follows

<parent> <groupId>some.project.config</groupId> <artifactId>project-config</artifactId> <version>x.x.xx</version> <relativePath /> </parent>

I need to use gradle for one application how can i use the properties of parent. Is it necessary to have parent also converted to gradle to use the properties?

Answer1:

You could use the <a href="https://maven.apache.org/ref/3.5.2/maven-model-builder/apidocs/org/apache/maven/model/building/ModelBuilder.html" rel="nofollow">Maven Model Builder API</a> to get the <a href="https://maven.apache.org/ref/3.5.2/maven-model-builder/apidocs/org/apache/maven/model/building/ModelBuildingResult.html#getEffectiveModel--" rel="nofollow">effective model</a>

See <a href="https://github.com/uklance/gradle-maven-transform/blob/master/plugin/src/main/groovy/com/lazan/maven/transform/MavenTransform.java#L138" rel="nofollow">MavenTransform.java</a> and <a href="https://github.com/uklance/gradle-maven-transform/blob/master/plugin/src/main/groovy/com/lazan/maven/transform/internal/ModelResolverImpl.java" rel="nofollow">ModelResolverImpl.java</a>

eg:

buildscript { dependencies { classpath 'org.apache.maven:maven-model:3.5.2' classpath 'org.apache.maven:maven-model-builder:3.5.2' } } configurations { pom } dependencies { pom 'some.project.config:project-config:x.x.xx@pom' } task copyPom(type: Copy) { from configurations.pom.singleFile into "$buildDir/pom" rename '.*', 'pom.xml' } task parsePom(dependsOn: copyPom) { inputs.file "$buildDir/pom/pom.xml" doLast { DefaultModelBuilderFactory factory = new DefaultModelBuilderFactory(); DefaultModelBuilder builder = factory.newInstance() ModelResolver modelResolver = new ModelResolverImpl(project) ModelBuildingRequest req = new DefaultModelBuildingRequest() req.pomFile = file("$buildDir/pom/pom.xml") req.modelResolver = modelResolver req.xxx = ... req.yyy = ... Model effectivePom = builder.build(req).getEffectiveModel() doStuff(effectivePom) } }

Recommend

  • In maven project How to download the library in source/binary, mentioned in the tag in POM file?
  • How to test Spring CrudRepository using @DataJpaTest in Spring boot 2.1.0.M4 using Junit 5
  • Using NSOutlineView as a file browser, starting from a given directory
  • My Angular + Spring Application routing does not work when deployed on TomCat
  • Google Cloud Builder - Gradle
  • JENKINS: ERROR when I try to use an older JDK for a specific maven project
  • Maven archetype generate with custom properties
  • PrimeFaces p:fileUpload Listener method is never invoked for mode=“simple”
  • how to exclude java sources from a third party jar?
  • AngularJS - ngBind and Bootstrap Switch
  • python struct.pack(): pack multiple datas in a list or a tuple
  • Regarding client side code generation from WSDL
  • Illegal reflective access operation
  • Can't run Appium tests on iOS 10 on real device
  • How can I create one checksum of two files in Maven to use it in the name of a directory
  • OAuth and the YouTube API
  • Is a .txt file created in VB different than one I'd randomly create?
  • maven jboss-as:start A required class was missing … org/sonaty…/ArtifactResolutionException
  • Adding directive inside the directive programatically
  • How do you create a Fuseki SPARQL server using the Apache Jena Java API?
  • How to pass nginx proxy url for socket
  • aapt.exe'' finished with non-zero exit value 1
  • Default parameter as generic type
  • Android Studio 1.3 RC3. Google Play services out of date. Requires 7571000 but found 6774470
  • gspread or such: help me get cell coordinates (not value)
  • How do I exclude a dependency in provided scope when running in Maven test scope?
  • Q promise. Difference between .when and .then
  • Cross-Platform Protobuf Serialization
  • Deserializing XML into class C#
  • Invalid access key error using credentials redeemed from an amazon open id token
  • Circular dependency while pushing http interceptor
  • How to format a variable of double type
  • InvalidAuthenticityToken between subdomains when logging in with Rails app
  • How to include full .NET prerequisite for Wix Burn installer
  • C# - Getting references of reference
  • coudnt use logback because of log4j
  • JaxB to read class hierarchy
  • costura.fody for a dll that references another dll
  • UserPrincipal.Current returns apppool on IIS
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize