Skip to content

Latest commit

 

History

History
113 lines (81 loc) · 3.98 KB

maven.md

File metadata and controls

113 lines (81 loc) · 3.98 KB

Maven

Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project's build, reporting and documentation from a central piece of information.


Maven

  • A software profject management & comprehension tool ( not Pacakge Management ! )
  • based on a POM (project object model)
  • including project's build, reporting & documentation

References

Configuration File

Add Dependecy

  • IntelliJ: ⌘ n in file pom.xml >> choose dependency
  • Then, enable Maven Auto Import
  • Topbar (taskbar) >> Code >> Generate…

Scope: provided

References

Differ provided from compile

  • dependencies are not transitive (as you mentioned)
  • provided scope is only available on the compilation and test classpath, whereas compile scope is available in all classpaths.
  • provided dependencies are not packaged

Compile means that you need the JAR for compiling and running the app. For a web application, as an example, the JAR will be placed in the WEB-INF/lib directory.

Provided means that you need the JAR for compiling, but at run time there is already a JAR provided by the environment so you don't need it packaged with your app. For a web app, this means that the JAR file will not be placed into the WEB-INF/lib directory.

For a web app, if the app server already provides the JAR (or its functionality), then use "provided" otherwise use "compile".

Resolve Package Conflictions

References

Install an Artifact to Local Repository

References

mvn install:install-file \
   -Dfile=<path-to-file> \
   -DgroupId=<group-id> \
   -DartifactId=<artifact-id> \
   -Dversion=<version> \
   -Dpackaging=<packaging> \
   -DgeneratePom=true

# e.g.
mvn install:install-file \
    -Dfile=icehe-sdk-1.0.0-20200604.105923-1.jar \
    -DgroupId=xyz.icehe \
    -DartifactId=icehe-sdk \
    -Dversion=1.0.0-SNAPSHOT \
    -Dpackaging=jar \
    -DgeneratePom=true

Skip deploy

References

pom.xml

    <build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
        </plugins>
    </build>

Others

试错经验

  • 子模块不要写变量, 显式写明 version
  • plugin 写 deply <configuration><deploy>true</deploy></configuration> 结果跳过了部署……
  • 依赖排错命令 mvn dependency:list/tree/analyze