@@ -73,4 +73,82 @@ publishing {
7373 }
7474 }
7575 }
76- }
76+ }
77+
78+
79+ // Force checksum generation
80+ // Generate checksums after publishing
81+ // Generate checksums and cleanup maven metadata after publishing
82+ tasks. register(' generateChecksumsAndCleanup' ) {
83+ dependsOn ' publishMavenPublicationToMavenLocal'
84+
85+ doLast {
86+ def userHome = System . getProperty(' user.home' )
87+ def localRepoPath = " ${ userHome} /.m2/repository"
88+ def groupPath = project. group. toString(). replace(' .' , ' /' )
89+ def artifactDir = new File (" ${ localRepoPath} /${ groupPath} /${ project.name} /${ project.version} " )
90+ def artifactParentDir = new File (" ${ localRepoPath} /${ groupPath} /${ project.name} " )
91+
92+ println " Processing ${ project.name} in: ${ artifactDir.absolutePath} "
93+
94+ if (artifactDir. exists()) {
95+ // Generate checksums for all relevant files
96+ artifactDir. listFiles(). findAll { file ->
97+ file. isFile() &&
98+ (file. name. endsWith(' .jar' ) || file. name. endsWith(' .pom' ) || file. name. endsWith(' .module' )) &&
99+ ! file. name. contains(' maven-metadata' ) &&
100+ ! file. name. endsWith(' .asc' ) && // Skip signature files
101+ ! file. name. endsWith(' .md5' ) && // Skip existing checksums
102+ ! file. name. endsWith(' .sha1' ) // Skip existing checksums
103+ }. each { file ->
104+ generateChecksumsFor(file)
105+ }
106+
107+ // Clean up maven-metadata-local.xml files
108+ cleanupMavenMetadata(artifactDir, artifactParentDir)
109+ }
110+ }
111+ }
112+
113+ def generateChecksumsFor (File file ) {
114+ // Generate MD5
115+ def md5File = new File (file. parentFile, " ${ file.name} .md5" )
116+ if (! md5File. exists()) {
117+ def md5 = java.security.MessageDigest . getInstance(' MD5' )
118+ file. eachByte(8192 ) { buffer , length ->
119+ md5. update(buffer, 0 , length)
120+ }
121+ md5File. text = md5. digest(). collect { String . format(' %02x' , it & 0xff ) }. join()
122+ println " Generated MD5 for ${ file.name} "
123+ }
124+
125+ // Generate SHA1
126+ def sha1File = new File (file. parentFile, " ${ file.name} .sha1" )
127+ if (! sha1File. exists()) {
128+ def sha1 = java.security.MessageDigest . getInstance(' SHA-1' )
129+ file. eachByte(8192 ) { buffer , length ->
130+ sha1. update(buffer, 0 , length)
131+ }
132+ sha1File. text = sha1. digest(). collect { String . format(' %02x' , it & 0xff ) }. join()
133+ println " Generated SHA1 for ${ file.name} "
134+ }
135+ }
136+
137+ def cleanupMavenMetadata (File versionDir , File artifactDir ) {
138+ // Delete maven-metadata-local.xml from version directory (e.g., 1.0.7-SNAPSHOT/)
139+ def versionMetadataFile = new File (versionDir, ' maven-metadata-local.xml' )
140+ if (versionMetadataFile. exists()) {
141+ boolean deleted = versionMetadataFile. delete()
142+ println " Deleted maven-metadata-local.xml from version directory: ${ deleted ? 'SUCCESS' : 'FAILED'} "
143+ }
144+
145+ // Delete maven-metadata-local.xml from artifact directory (e.g., method-analyzer-core/)
146+ def artifactMetadataFile = new File (artifactDir, ' maven-metadata-local.xml' )
147+ if (artifactMetadataFile. exists()) {
148+ boolean deleted = artifactMetadataFile. delete()
149+ println " Deleted maven-metadata-local.xml from artifact directory: ${ deleted ? 'SUCCESS' : 'FAILED'} "
150+ }
151+ }
152+
153+ // Chain the tasks
154+ publishToMavenLocal. finalizedBy generateChecksumsAndCleanup
0 commit comments