技術共有

pom.xml の重要なタグの紹介

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

Maven プロジェクトでは、pom.xml このファイルは、プロジェクトの依存関係、プラグイン、ビルド構成などを定義するプロジェクト オブジェクト モデル (POM) の構成ファイルです。以下はpom.xml ファイル内のいくつかの重要なタグとその機能:

  1. <modelVersion>

    • POM モデルのバージョンを定義します。現在一般的に使用されているバージョンは、4.0.0
    <modelVersion>4.0.0</modelVersion>
    
    • 1
  2. <groupId>

    • プロジェクトのグループ ID を定義します。通常は組織または会社を表します。
    <groupId>com.example</groupId>
    
    • 1
  3. <artifactId>

    • プロジェクトのアーティファクト ID (プロジェクトの名前) を定義します。
    <artifactId>my-project</artifactId>
    
    • 1
  4. <version>

    • プロジェクトのバージョン番号を定義します。
    <version>1.0.0</version>
    
    • 1
  5. <packaging>

    • プロジェクトをパッケージ化する方法を定義します。たとえば、 jarwarpom 待って。デフォルトはjar
    <packaging>jar</packaging>
    
    • 1
  6. <name>

    • プロジェクトの名前。
    <name>My Project</name>
    
    • 1
  7. <description>

    • プロジェクトの説明。
    <description>This is a sample project</description>
    
    • 1
  8. <url>

    • プロジェクトのホームページの URL。
    <url>http://www.example.com</url>
    
    • 1
  9. <dependencies>

    • プロジェクトの依存関係を定義します。それぞれの依存関係で使用されるのは、 <dependency> ラベルパッケージ。
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>5.3.8</version>
        </dependency>
    </dependencies>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
  10. <dependencyManagement>

    • プロジェクトの依存関係を一元管理するために使用されるバージョン。サブモジュールは、バージョンを指定せずにこれらの依存関係を継承できます。
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-core</artifactId>
                <version>5.3.8</version>
            </dependency>
        </dependencies>
    </dependencyManagement>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
  11. <repositories>

    • プロジェクトが依存するリモート リポジトリを定義します。
    <repositories>
        <repository>
            <id>central</id>
            <url>https://repo.maven.apache.org/maven2</url>
        </repository>
    </repositories>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
  12. <build>

    • プラグイン構成、リソース構成などのビルド関連の構成が含まれます。
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
  13. <properties>

    • Maven ビルドで変数を定義します。
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
    
    • 1
    • 2
    • 3
    • 4
  14. <profiles>

    • さまざまな環境で使用できるさまざまなビルド構成を定義します。
    <profiles>
        <profile>
            <id>dev</id>
            <properties>
                <env>development</env>
            </properties>
        </profile>
    </profiles>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

これらのタグは、 pom.xml Maven プロジェクトを構成および管理するための基本フレームワーク。各タグは特定の目的を果たし、開発者がプロ​​ジェクトのさまざまな側面を定義するのに役立ちます。