Maven常见配置及本地仓库清理(Linux)

常见配置


<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.0modelVersion>
    
    
    <groupId>com.codedancing.mavengroupId>
    <artifactId>TestartifactId>
    <version>1.0.0version>
    
    <packaging>jarpackaging>

    
    <name>Maven-Testname>

    
    <description>
        这是一个maven的测试工程
    description>

    
    <developers>
        <developer>
            <id>001id>
            <name>codedancingname>
            <email>[email protected]email>
            <roles>
                <role>Creatorrole>
            roles>
        developer>
    developers>

    
    <properties>
        
        <encoding>UTF-8encoding>
        
        <java.version>1.8java.version>
        
        
        <maven.compiler.source>${java.version}maven.compiler.source>
        <maven.compiler.target>${java.version}maven.compiler.target>
        
        <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
    properties>

    
    <dependencies>
        
        <dependency>
            <groupId>junitgroupId>
            <artifactId>junitartifactId>
            <version>4.12version>
            <scope>testscope>
        dependency>
    dependencies>

    
    <build>
     	
        <plugins>
			
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-compiler-pluginartifactId>
                <version>3.1version>
                <configuration>
                    <source>1.8source>
                    <target>1.8target>
                    <encoding>UTF-8encoding>
                configuration>
            plugin>
            
            
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-resources-pluginartifactId>
                <version>3.1.0version>
                <configuration>
                    <encoding>UTF-8encoding>
                configuration>
            plugin>
            
            
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-dependency-pluginartifactId>
                <version>3.1.1version>
                
                <executions>
                    <execution>
                        <id>copyid>
                        <phase>packagephase>
                        <goals>
                            <goal>copy-dependenciesgoal>
                        goals>
                        <configuration>
                            
                            <outputDirectory>
                                ${project.build.directory}/lib
                            outputDirectory>
                        configuration>
                    execution>
                executions>
            plugin>

            
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-jar-pluginartifactId>
                <version>3.1.0version>
                
                <configuration>
                    <archive>
                        
                        <manifest>
                            
                        <mainClass>
                            com.codedancing.maven.TestMaven
                        mainClass>
                            
                            <addClasspath>trueaddClasspath>
                            
                            <classpathPrefix>/libclasspathPrefix>
                        manifest>
                    archive>
                configuration>
            plugin>
        plugins>
    build>

project>


本地仓库清理(Linux)

当 maven下载依赖时,如果网络中断,会产生一些 .lastUpdated 文件和 unknown 文件夹,可能导致无法正常下载依赖,可以使用一下命令清理

进入 maven 本地仓库目录,执行
find ./ -name *.lastUpdated -o -name unknown | xargs rm -rf

你可能感兴趣的:(Apache,Maven)