-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-corporate-network.ps1
More file actions
113 lines (99 loc) · 5.03 KB
/
setup-corporate-network.ps1
File metadata and controls
113 lines (99 loc) · 5.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# Corporate Network Gradle Setup Script
# Run this script to configure environment for SSL issues
Write-Host "🔧 Setting up Gradle for Corporate Network..." -ForegroundColor Green
# Set Java system properties for SSL bypassing
$env:JAVA_OPTS = "-Dtrust_all_cert=true -Dcom.sun.net.ssl.checkRevocation=false -Dsun.security.ssl.allowUnsafeRenegotiation=true -Djava.net.useSystemProxies=true"
$env:GRADLE_OPTS = "-Dtrust_all_cert=true -Dcom.sun.net.ssl.checkRevocation=false -Dsun.security.ssl.allowUnsafeRenegotiation=true -Djava.net.useSystemProxies=true"
Write-Host "✅ Environment variables set:" -ForegroundColor Yellow
Write-Host " JAVA_OPTS: $env:JAVA_OPTS"
Write-Host " GRADLE_OPTS: $env:GRADLE_OPTS"
# Check Java version
Write-Host "`n🔍 Checking Java installation..." -ForegroundColor Green
try {
$javaVersion = java -version 2>&1 | Select-String "version"
Write-Host "✅ Java found: $javaVersion" -ForegroundColor Yellow
}
catch {
Write-Host "❌ Java not found in PATH. Please install Java 17+ first." -ForegroundColor Red
exit 1
}
# Method 1: Try with system proxy
Write-Host "`n🌐 Method 1: Attempting build with system proxy settings..." -ForegroundColor Green
try {
.\gradlew.bat build --stacktrace
Write-Host "✅ Build successful with system proxy!" -ForegroundColor Green
exit 0
}
catch {
Write-Host "❌ Method 1 failed. Trying alternative approaches..." -ForegroundColor Yellow
}
# Method 2: Manual Gradle download
Write-Host "`n📦 Method 2: Manual Gradle download..." -ForegroundColor Green
$gradleUrl = "https://services.gradle.org/distributions/gradle-8.11.1-all.zip"
$gradleZip = "gradle-8.11.1-all.zip"
$gradleDir = "gradle-8.11.1"
if (Test-Path $gradleZip) {
Write-Host "✅ Gradle zip already exists, skipping download" -ForegroundColor Yellow
}
else {
Write-Host "⬇️ Downloading Gradle manually..." -ForegroundColor Yellow
try {
# Try with system proxy first
Invoke-WebRequest -Uri $gradleUrl -OutFile $gradleZip -UseBasicParsing
Write-Host "✅ Download successful!" -ForegroundColor Green
}
catch {
Write-Host "❌ Direct download failed. You may need to:" -ForegroundColor Red
Write-Host " 1. Download manually from: $gradleUrl" -ForegroundColor Red
Write-Host " 2. Place it in the current directory as: $gradleZip" -ForegroundColor Red
Write-Host " 3. Run this script again" -ForegroundColor Red
# Try alternative download with proxy bypass
Write-Host "`n🔄 Trying download with proxy bypass..." -ForegroundColor Yellow
try {
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
$webClient = New-Object System.Net.WebClient
$webClient.DownloadFile($gradleUrl, $gradleZip)
Write-Host "✅ Alternative download successful!" -ForegroundColor Green
}
catch {
Write-Host "❌ All download methods failed. Manual intervention required." -ForegroundColor Red
exit 1
}
}
}
# Extract Gradle if needed
if (-not (Test-Path $gradleDir)) {
Write-Host "📂 Extracting Gradle..." -ForegroundColor Yellow
Expand-Archive -Path $gradleZip -DestinationPath . -Force
Write-Host "✅ Gradle extracted!" -ForegroundColor Green
}
# Set up Gradle wrapper to use local Gradle
Write-Host "`n⚙️ Configuring Gradle wrapper..." -ForegroundColor Green
$gradleBin = Join-Path $gradleDir "bin\gradle.bat"
if (Test-Path $gradleBin) {
Write-Host "✅ Local Gradle found at: $gradleBin" -ForegroundColor Yellow
# Try building with local Gradle
Write-Host "`n🔨 Attempting build with local Gradle..." -ForegroundColor Green
& $gradleBin build --stacktrace
if ($LASTEXITCODE -eq 0) {
Write-Host "✅ Build successful with local Gradle!" -ForegroundColor Green
}
else {
Write-Host "❌ Build failed even with local Gradle." -ForegroundColor Red
}
}
else {
Write-Host "❌ Local Gradle not found after extraction." -ForegroundColor Red
}
# Provide troubleshooting guidance
Write-Host "`n📋 Additional Troubleshooting Steps:" -ForegroundColor Cyan
Write-Host " 1. Contact your IT team for corporate certificates" -ForegroundColor White
Write-Host " 2. Ask for proxy configuration details" -ForegroundColor White
Write-Host " 3. Request whitelisting of gradle.org and services.gradle.org" -ForegroundColor White
Write-Host " 4. Consider using a corporate Nexus/Artifactory repository" -ForegroundColor White
Write-Host " 5. Try building from a different network (home/mobile hotspot)" -ForegroundColor White
Write-Host "`n🔧 If SSL issues persist, you can manually configure:" -ForegroundColor Cyan
Write-Host " - Edit gradle.properties to add your proxy settings" -ForegroundColor White
Write-Host " - Import corporate certificates to Java keystore" -ForegroundColor White
Write-Host " - Use offline Gradle distribution" -ForegroundColor White