How do I find out about BOM support in Java Gradle?

Asked 1 years ago, Updated 1 years ago, 423 views

I refer to the following article.
https://blogs.lisb.direct/entry/2019-07-01-083000

Gradle has a mechanism called BOM.For example, if you write the following in dependencies,
[2]There is no version specification in the library in the line
[1]I understand that the general feature is that the library version of [2] is treated as 1.4.199 because of the line in .

 dependencies {
  implementation platform('org.springframework.boot:spring-boot-starter-parent:2.1.5.RELEASE') // [1]
  runtimeOnly'com.h2database:h2'//[2]
}

I would like you to tell me how to know this in an unknown library.
The above springframework is a well-known library, so if you search for it, there are countless explanatory pages. I would like to know how to find a list of [2] that supports [1] even if it is not a well-known library.

The above org.springframework.boot:spring-boot-starter-parent:2.1.5.RELEASE mavenCentral page is as follows, but
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent/2.1.5.RELEASE
↑From this page, org.springframework.boot:spring-boot-starter-parent:2.1.5.RELEASE is
"It's BOM" and "com.h2database:h2 is specified as version 1.4.199"
How do I read ?

For example, if you want to look at a library named spring-framework in node.js,
Access the following URL from the package name:
https://www.npmjs.com/package/spring-framework
There is a link called Repository on this page, so go to the github page of ↓ below and
https://github.com/ArseniyBorezkiy/spring-js
If you open the package.json file, you can find all the metadata in this library.

In some cases, repository is not available, but you can still download package.json from npmjs.com via curl.
In this way, you can find information from any minor commentary or package that doesn't even have a properly written readme, as long as you can open a text file called package.json.

How do I know the primary information of library metadata in the library specified in Java gradle as above?

java gradle

2023-01-03 08:45

1 Answers

BOM (Bill of Materials) refers to Maven POM (known as pom.xml, such as build.gradle in Gradle), which inherits the https://search.maven.org/.

For example, if org.springframework.boot:spring-boot-starter-parent:2.1.5.RELEASE,

In the link to the , click

<packaging>pom</packaging>

You can see that is specified.

However, this one also has a parent from which to inherit (<parent> is specified), so you need to look at that parent as well.

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-dependencies</artifactId>
    <version>2.1.5.RELEASE</version>
    <relativePath>../../spring-boot-dependencies</relativePath>
  </parent>

If you search the search window for things like "org.springframework.boot:spring-boot-dependent:2.1.5.RELEASE", the following will be a hit:

Now you can see that the following information is defined:

<properties>
...
    <h2.version>1.4.199</h2.version>
<dependencyManagement>
    <dependencies>
...
      <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>${h2.version}</version>
      </dependency>

If you even know that packaging is pom, it may be easier to create a dummy Maven project and display that information.
(*Gradle may have a similar function, but I don't know.)

Specifically, create the following pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.github.yukihane.examples</groupId>
  <artifactId> jaso93141</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.5.RELEASE</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
</project>

Run the following command (help:effective-pom) to print a POM with inheritance open:

 mvn help:effective-pom

Output:

...
  <dependencyManagement>
    <dependencies>
...
      <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>1.4.199</version>
      </dependency>
...


2023-01-03 09:09

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.