Skip to content

Commit 5a6ee5e

Browse files
committed
Publish to Central Repository
1 parent e473ffc commit 5a6ee5e

File tree

7 files changed

+167
-6
lines changed

7 files changed

+167
-6
lines changed

client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<plugin>
2222
<groupId>org.sonatype.central</groupId>
2323
<artifactId>central-publishing-maven-plugin</artifactId>
24-
<version>0.7.0</version>
24+
<version>0.8.0</version>
2525
<extensions>true</extensions>
2626
<configuration>
2727
<publishingServerId>central</publishingServerId>

okhttp-modules/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<plugin>
2323
<groupId>org.sonatype.central</groupId>
2424
<artifactId>central-publishing-maven-plugin</artifactId>
25-
<version>0.7.0</version>
25+
<version>0.8.0</version>
2626
<extensions>true</extensions>
2727
<configuration>
2828
<publishingServerId>central</publishingServerId>

pluggable-storage/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<plugin>
2424
<groupId>org.sonatype.central</groupId>
2525
<artifactId>central-publishing-maven-plugin</artifactId>
26-
<version>0.7.0</version>
26+
<version>0.8.0</version>
2727
<extensions>true</extensions>
2828
<configuration>
2929
<publishingServerId>central</publishingServerId>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@
216216
<plugin>
217217
<groupId>org.sonatype.central</groupId>
218218
<artifactId>central-publishing-maven-plugin</artifactId>
219-
<version>0.7.0</version>
219+
<version>0.8.0</version>
220220
<extensions>true</extensions>
221221
<configuration>
222222
<publishingServerId>central</publishingServerId>

redis-wrapper/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
<plugin>
4646
<groupId>org.sonatype.central</groupId>
4747
<artifactId>central-publishing-maven-plugin</artifactId>
48-
<version>0.7.0</version>
48+
<version>0.8.0</version>
4949
<extensions>true</extensions>
5050
<configuration>
5151
<publishingServerId>central</publishingServerId>

testing/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<plugin>
3434
<groupId>org.sonatype.central</groupId>
3535
<artifactId>central-publishing-maven-plugin</artifactId>
36-
<version>0.7.0</version>
36+
<version>0.8.0</version>
3737
<extensions>true</extensions>
3838
<configuration>
3939
<publishingServerId>central</publishingServerId>

update_maven_settings.sh

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
#!/bin/bash
2+
3+
# Script to update Maven settings.xml with Central Repository credentials using xmlstarlet
4+
5+
# ANSI color codes
6+
GREEN='\033[0;32m'
7+
YELLOW='\033[0;33m'
8+
BLUE='\033[0;34m'
9+
RED='\033[0;31m'
10+
NC='\033[0m' # No Color
11+
12+
# Check if xmlstarlet is installed
13+
if ! command -v xmlstarlet &> /dev/null; then
14+
echo -e "${RED}Error: xmlstarlet is not installed.${NC}"
15+
echo "Please install xmlstarlet first:"
16+
echo " macOS: brew install xmlstarlet"
17+
echo " Debian/Ubuntu: sudo apt-get install xmlstarlet"
18+
echo " RHEL/CentOS/Fedora: sudo yum install xmlstarlet"
19+
echo "Then run this script again."
20+
exit 1
21+
fi
22+
23+
# Default values
24+
DEFAULT_SETTINGS_PATH="$HOME/.m2/settings.xml"
25+
DEFAULT_SERVER_ID="central"
26+
27+
echo -e "${BLUE}Maven Settings.xml Update Script${NC}"
28+
echo "This script will update your Maven settings.xml with Central Repository credentials."
29+
echo
30+
31+
# Ask for settings.xml path or use default
32+
read -p "Path to settings.xml [$DEFAULT_SETTINGS_PATH]: " SETTINGS_PATH
33+
SETTINGS_PATH=${SETTINGS_PATH:-$DEFAULT_SETTINGS_PATH}
34+
35+
# Variables to store existing values
36+
EXISTING_USERNAME=""
37+
EXISTING_PASSWORD=""
38+
39+
# Extract existing values if settings.xml exists
40+
if [ -f "$SETTINGS_PATH" ] && command -v xmlstarlet &> /dev/null; then
41+
# Check if the file is valid XML
42+
if xmlstarlet val "$SETTINGS_PATH" &> /dev/null; then
43+
echo -e "${YELLOW}Reading existing settings from ${SETTINGS_PATH}...${NC}"
44+
45+
# Extract existing server ID
46+
DEFAULT_SERVER_ID=$(xmlstarlet sel -t -v "/settings/servers/server[1]/id" "$SETTINGS_PATH" 2>/dev/null || echo "$DEFAULT_SERVER_ID")
47+
48+
# Extract existing username and password for the server
49+
EXISTING_USERNAME=$(xmlstarlet sel -t -v "/settings/servers/server[id='$DEFAULT_SERVER_ID']/username" "$SETTINGS_PATH" 2>/dev/null || echo "")
50+
EXISTING_PASSWORD=$(xmlstarlet sel -t -v "/settings/servers/server[id='$DEFAULT_SERVER_ID']/password" "$SETTINGS_PATH" 2>/dev/null || echo "")
51+
fi
52+
fi
53+
54+
# Ask for server ID or use default/existing
55+
read -p "Server ID [$DEFAULT_SERVER_ID]: " SERVER_ID
56+
SERVER_ID=${SERVER_ID:-$DEFAULT_SERVER_ID}
57+
58+
# Ask for username (show existing if available)
59+
USERNAME_PROMPT="Username"
60+
if [ -n "$EXISTING_USERNAME" ]; then
61+
USERNAME_PROMPT="Username (current: $EXISTING_USERNAME)"
62+
fi
63+
read -p "$USERNAME_PROMPT: " USERNAME
64+
USERNAME=${USERNAME:-$EXISTING_USERNAME}
65+
66+
# Ask for password (indicate if existing)
67+
PASSWORD_PROMPT="Password"
68+
if [ -n "$EXISTING_PASSWORD" ]; then
69+
PASSWORD_PROMPT="Password (leave empty to keep current)"
70+
fi
71+
read -s -p "$PASSWORD_PROMPT: " PASSWORD
72+
echo
73+
# Only use existing password if the user didn't enter a new one
74+
if [ -z "$PASSWORD" ] && [ -n "$EXISTING_PASSWORD" ]; then
75+
PASSWORD="$EXISTING_PASSWORD"
76+
fi
77+
78+
# Create .m2 directory if it doesn't exist
79+
M2_DIR=$(dirname "$SETTINGS_PATH")
80+
mkdir -p "$M2_DIR"
81+
82+
# No GPG configuration needed
83+
84+
# Function to create a new settings.xml file
85+
create_new_settings() {
86+
echo -e "${YELLOW}Creating new settings.xml file...${NC}"
87+
cat > "$SETTINGS_PATH" << EOF
88+
<?xml version="1.0" encoding="UTF-8"?>
89+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
90+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
91+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
92+
<servers>
93+
<server>
94+
<id>$SERVER_ID</id>
95+
<username>$USERNAME</username>
96+
<password>$PASSWORD</password>
97+
</server>
98+
</servers>
99+
</settings>
100+
EOF
101+
}
102+
103+
# Check if settings.xml exists
104+
if [ -f "$SETTINGS_PATH" ]; then
105+
echo -e "${YELLOW}Existing settings.xml found. Backing up to ${SETTINGS_PATH}.bak${NC}"
106+
cp "$SETTINGS_PATH" "${SETTINGS_PATH}.bak"
107+
108+
# Check if the file is valid XML
109+
if ! xmlstarlet val "$SETTINGS_PATH" &> /dev/null; then
110+
echo -e "${RED}Warning: The existing settings.xml is not valid XML.${NC}"
111+
read -p "Do you want to create a new settings.xml file? (y/n): " CREATE_NEW
112+
if [[ $CREATE_NEW =~ ^[Yy]$ ]]; then
113+
create_new_settings
114+
else
115+
echo -e "${RED}Exiting without making changes.${NC}"
116+
exit 1
117+
fi
118+
else
119+
# Check if servers element exists
120+
if ! xmlstarlet sel -t -v "/settings/servers" "$SETTINGS_PATH" &> /dev/null; then
121+
echo -e "${YELLOW}No servers section found. Adding servers section...${NC}"
122+
xmlstarlet ed --inplace \
123+
-s "/settings" -t elem -n "servers" \
124+
-s "/settings/servers" -t elem -n "server" \
125+
-s "/settings/servers/server" -t elem -n "id" -v "$SERVER_ID" \
126+
-s "/settings/servers/server" -t elem -n "username" -v "$USERNAME" \
127+
-s "/settings/servers/server" -t elem -n "password" -v "$PASSWORD" \
128+
"$SETTINGS_PATH"
129+
else
130+
# Check if server with this ID already exists
131+
if xmlstarlet sel -t -v "/settings/servers/server[id='$SERVER_ID']" "$SETTINGS_PATH" &> /dev/null; then
132+
echo -e "${YELLOW}Server with ID '$SERVER_ID' already exists. Updating credentials...${NC}"
133+
# Update existing server credentials
134+
xmlstarlet ed --inplace \
135+
-u "/settings/servers/server[id='$SERVER_ID']/username" -v "$USERNAME" \
136+
-u "/settings/servers/server[id='$SERVER_ID']/password" -v "$PASSWORD" \
137+
"$SETTINGS_PATH"
138+
else
139+
echo -e "${YELLOW}Adding new server with ID '$SERVER_ID'...${NC}"
140+
# Add new server to existing servers section
141+
xmlstarlet ed --inplace \
142+
-s "/settings/servers" -t elem -n "server" \
143+
-s "/settings/servers/server[last()]" -t elem -n "id" -v "$SERVER_ID" \
144+
-s "/settings/servers/server[last()]" -t elem -n "username" -v "$USERNAME" \
145+
-s "/settings/servers/server[last()]" -t elem -n "password" -v "$PASSWORD" \
146+
"$SETTINGS_PATH"
147+
fi
148+
fi
149+
fi
150+
else
151+
create_new_settings
152+
fi
153+
154+
# Make sure the file has the right permissions
155+
chmod 600 "$SETTINGS_PATH"
156+
157+
echo -e "${GREEN}Maven settings.xml updated successfully at $SETTINGS_PATH${NC}"
158+
echo -e "${GREEN}Server ID: $SERVER_ID${NC}"
159+
echo -e "${GREEN}Username: $USERNAME${NC}"
160+
echo -e "${GREEN}Password: ********${NC}"
161+

0 commit comments

Comments
 (0)