#!/bin/bash

echo "修复Maven编译问题..."

# 删除本地Maven缓存中的问题依赖
echo "清理本地Maven仓库缓存..."
rm -rf ~/.m2/repository/org/springframework/boot/spring-boot-maven-plugin/3.1.5/

# 创建临时的settings.xml文件，强制使用Maven Central仓库
mkdir -p ~/.m2
cat > ~/.m2/settings.xml << EOF
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                              http://maven.apache.org/xsd/settings-1.0.0.xsd">
    
    <mirrors>
        <mirror>
            <id>central</id>
            <mirrorOf>*</mirrorOf>
            <name>Maven Central Repository</name>
            <url>https://repo1.maven.org/maven2</url>
        </mirror>
    </mirrors>
    
    <profiles>
        <profile>
            <id>central-repo</id>
            <repositories>
                <repository>
                    <id>central</id>
                    <name>Central Repository</name>
                    <url>https://repo1.maven.org/maven2</url>
                    <layout>default</layout>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>central</id>
                    <name>Central Repository</name>
                    <url>https://repo1.maven.org/maven2</url>
                    <layout>default</layout>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                    <releases>
                        <updatePolicy>never</updatePolicy>
                    </releases>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>
    
    <activeProfiles>
        <activeProfile>central-repo</activeProfile>
    </activeProfiles>
</settings>
EOF

echo "已创建临时Maven settings.xml文件"
echo "尝试重新编译项目..."

# 强制更新依赖并编译
mvn -U clean compile -DskipTests

echo "编译完成！"
echo "如果编译成功，可以删除临时配置文件：rm ~/.m2/settings.xml"