MAVEN development practice -- problem solving & Precautions

1, Common problems and Solutions
1. How to convert an ordinary project into a maven project in idea?
Right click add as maven project in idea to change a normal project into a maven project.
2. The maven dependency in idea is still displayed after being deleted. May it be due to cache problems?
ide>file>invalidate caches
3. How to avoid dependency conflict?
Every time you add dependencies, you should check whether there are jar package conflicts. It is recommended to install the plug-in maven helper (package dependency analysis and troubleshooting tool)
4.maven warehouse cannot normally obtain dependent packages?
Manually import -- run under the jar Directory:
MVN install: install file - dfile = path of jar package - Contents in DgroupId=gruopId - contents of dartifactid = actifacid - contents of Dversion=version - Dpackaging=jar
5. After the new version of the component is released, is the dependent party still pulling the old code?
Check whether the target warehouse has the same gav and other incorrect releases, and whether a certain level of warehouse fetches the old version cache, and then pull again after deleting the target package
You can also configure the remote package update and pull frequency and policy in maven configuration
<profile>
    <id>nexus</id>
    <repositories>
        <repository>
            <id>central</id>
            <url>http://central</url>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </releases>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </snapshots>
        </repository>
    </repositories>
</profile>

 

2, Precautions

1. The environment variable needs to correspond to the root directory of maven
2. To test mvn -v in cmd, you need to start cmd after configuration, similar to caching
3. Need to download network resources
4. By default, maven's local library points to: C: \ users \ admin \ m2\repository
5. When configuring LocalRepository, use '\' to translate: E:\envrionment\ali_repo
6. Configure Internet access
 
Note: Alibaba private server (agent = > Maven central database, private resources)
7. Resource positioning:
All maven related resources will have a unique central information segment to locate the resources;
It consists of three labels:
8.pom resource structure and significance
remote.repositories
**. The jar package used by jar is the same as the jar package for custom manually imported projects
**. POM: the core management document of maven; All resources are transformed by maven
**. javadoc.jar: explanation of documents, APIs and resources
**. sources.jar: source package. You can import the source package to view the source code
**. sha1 hash calculation to judge packet loss
8. Which archetype to choose?
For different projects that need to be maintained, they are essentially jar resources. The purpose of creating and maintaining them according to maven is different
Create projects with different skeletons and call different jar packages to maintain different projects, for example:
quickstart defaults to a normal java project, and webapp is a web application. Corresponding skeleton files are required locally
Finally, a maven project was created in the designated workspace
9. Create a project in workspace and operate the project command in POM XML file location
10. Empty items
mvn clean
11. The navigator in eclipse displays the project directory by disk, which is used for pasting
12.jar package is a maven project developed by the human team; Dependencies can be passed between Maven projects
13.maven uses jar package label
 
14. Set the external warehouse address
<repositories>
    <repository>
        <id>aliyun</id>
        <name>Alibaba cloud public warehouse</name>
        <url>https://maven.aliyun.com/repository/public</url>
    </repository>
    <repository>
        <id>spring</id>
        <url>https://maven.aliyun.com/repository/spring</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

15. When working together, others told us that their snapshot version had changed. When we want to update in time, we can mvn clean install -U force the update, or delete the corresponding version of the jar package to complete the download of the new version of the jar package

 16. Define component publishing address

<!--version management :Define your project(git Warehouse location)-->
    <scm>
        <connection>scm:git:https://gitee.com/xxxx/xxxx.git</connection>
        <developerConnection>scm:git:https://gitee.com/xxxx/xxxx.git</developerConnection>
        <url>https://gitee.com/xxxx/xxxx</url>
    </scm>
    <build>
        <pluginManagement>
            <plugins>
                <!-- release plug-in unit -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-release-plugin</artifactId>
                    <version>2.1</version>
                    <configuration>
                        <mavenExecutorId>forked-path</mavenExecutorId>
                        <useReleaseProfile>false</useReleaseProfile>
                        <arguments>-Paliyun-release</arguments>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
    <profiles>
        <!-- Define the to publish to the warehouse source and javadoc -->
        <profile>
            <id>aliyun-release</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <version>2.1.2</version>
                        <executions>
                            <execution>
                                <id>attach-sources</id>
                                <goals>
                                    <goal>jar-no-fork</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>attach-javadocs</id>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

 17. Use < scope > to control the life cycle of dependency compilation, and use the < exclude > tag to exclude useless or conflicting dependencies

 

 
 
 

Posted by mbhcool on Tue, 24 May 2022 09:13:01 +0300