<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ufuk Güler on Medium]]></title>
        <description><![CDATA[Stories by Ufuk Güler on Medium]]></description>
        <link>https://medium.com/@ufuk.guler?source=rss-3aecc3197d04------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Kcmg5eSNT1db4aJk0orrtQ@2x.jpeg</url>
            <title>Stories by Ufuk Güler on Medium</title>
            <link>https://medium.com/@ufuk.guler?source=rss-3aecc3197d04------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 25 Nov 2026 02:14:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ufuk.guler/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Obfuscate Spring Boot Applications with Proguard Maven Plugin]]></title>
            <link>https://medium.com/@ufuk.guler/obfuscate-spring-boot-applications-with-proguard-maven-plugin-1f34bb871776?source=rss-3aecc3197d04------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f34bb871776</guid>
            <category><![CDATA[obfuscation]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[proguard]]></category>
            <dc:creator><![CDATA[Ufuk Güler]]></dc:creator>
            <pubDate>Sun, 03 Nov 2024 20:27:22 GMT</pubDate>
            <atom:updated>2024-11-04T07:06:01.026Z</atom:updated>
            <content:encoded><![CDATA[<h3>ProGuard</h3><blockquote><em>ProGuard is an open-sourced Java class file shrinker, optimizer, obfuscator, and preverifier. As a result, ProGuard processed applications and libraries are smaller, faster, and somewhat hardened against reverse engineering. </em>(<a href="https://www.guardsquare.com/manual/configuration/usage">Proguard Manual</a>)</blockquote><p>ProGuard is an open-source and free tool that allows you to shrink, optimize, and obfuscate Java-based codes. It detects unused classes, fields, methods, and attributes and deletes them at build time. Proguard is part of the Android SDK and is used to get the release build.</p><h3>What is Code Obfuscation?</h3><p>This name is given to a “confusing” operation applied by changing the terms of classes and variables in a way that makes them difficult to read and understand. As a dictionary meaning, obfuscation means “the act or an instance of making something obscure, dark, or difficult to understand”. (<a href="https://www.dictionary.com/browse/obfuscation">source</a>)</p><h3>Why Is Obfuscation Necessary?</h3><p>Obfuscation is essential to safeguard proprietary algorithms and project-specific know-how. When our code is deployed on third-party servers or distributed as an Android app, it can potentially be accessed by end users. This makes it vital to protect our intellectual property and hard work. Obfuscation helps by reducing and optimizing the code, which not only decreases file size but can also positively impact application performance.</p><h3>How to Integrate ProGuard into a Spring Project</h3><p>ProGuard can be incorporated directly or via build tools like Maven and Gradle. In Maven, ProGuard integration can be achieved through an unofficial open-source plugin, while in Gradle, an official plugin is available for seamless addition to your dependencies.</p><p>This setup enables you to utilize ProGuard’s capabilities within your Spring project, optimizing and securing your code.</p><p>Here’s the repository: <a href="https://github.com/ufukguler/book-portal/tree/reactive">https://github.com/ufukguler/book-portal/tree/reactive</a></p><ol><li>First of all, you need to add the following build steps to the pom.xml file of our project:</li></ol><pre>&lt;profiles&gt;<br>    &lt;profile&gt;<br>        &lt;id&gt;proguard&lt;/id&gt;<br>        &lt;build&gt;<br>            &lt;plugins&gt;<br>                &lt;plugin&gt;<br>                    &lt;groupId&gt;com.github.wvengen&lt;/groupId&gt;<br>                    &lt;artifactId&gt;proguard-maven-plugin&lt;/artifactId&gt;<br>                    &lt;version&gt;2.5.3&lt;/version&gt;<br>                    &lt;executions&gt;<br>                        &lt;execution&gt;<br>                            &lt;phase&gt;package&lt;/phase&gt;<br>                            &lt;goals&gt;<br>                                &lt;goal&gt;proguard&lt;/goal&gt;<br>                            &lt;/goals&gt;<br>                        &lt;/execution&gt;<br>                    &lt;/executions&gt;<br>                    &lt;configuration&gt;<br>                        &lt;injar&gt;${project.build.finalName}.jar&lt;/injar&gt;<br>                        &lt;outjar&gt;${project.build.finalName}.jar&lt;/outjar&gt;<br>                        &lt;obfuscate&gt;true&lt;/obfuscate&gt;<br>                        &lt;proguardInclude&gt;proguard.conf&lt;/proguardInclude&gt;<br>                    &lt;/configuration&gt;<br>                &lt;/plugin&gt;<br>                &lt;plugin&gt;<br>                    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br>                    &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;<br>                    &lt;executions&gt;<br>                        &lt;execution&gt;<br>                            &lt;goals&gt;<br>                                &lt;goal&gt;repackage&lt;/goal&gt;<br>                            &lt;/goals&gt;<br>                            &lt;configuration&gt;<br>                                &lt;mainClass&gt;com.bookportal.api.AppMediaApplication&lt;/mainClass&gt;<br>                            &lt;/configuration&gt;<br>                        &lt;/execution&gt;<br>                    &lt;/executions&gt;<br>                &lt;/plugin&gt;<br>            &lt;/plugins&gt;<br>        &lt;/build&gt;<br>    &lt;/profile&gt;<br>&lt;/profiles&gt;</pre><p>2. Then create a file named <em>proguard.conf</em> in the main directory of the project and paste it into it:</p><pre>-dontshrink<br>-dontoptimize<br>-useuniqueclassmembernames<br>-adaptclassstrings<br>-dontnote<br>-ignorewarnings<br>-dontwarn<br><br>-keep class * extends org.springframework.boot.web.support.SpringBootServletInitializer<br>-keep class * extends org.springframework.boot.loader.**<br>-keepclasseswithmembers public class * { public static void main(java.lang.String[]);}<br>-keepclassmembers class * {<br>     @org.springframework.beans.factory.annotation.Autowired *;<br>     @org.springframework.beans.factory.annotation.Qualifier *;<br>     @org.springframework.beans.factory.annotation.Value *;<br>     @org.springframework.beans.factory.annotation.Required *;<br>     @org.springframework.context.annotation.Bean *;<br>     @org.springframework.context.annotation.Primary *;<br>     @org.springframework.boot.context.properties.ConfigurationProperties *;<br>     @org.springframework.boot.context.properties.EnableConfigurationProperties *;<br><br>     ## thymeleaf (for html templates)<br>     *** get*();<br>     void set*(***);<br>}<br>-keep @org.springframework.cache.annotation.EnableCaching class *<br>-keep @org.springframework.context.annotation.Configuration class *<br>-keep @org.springframework.boot.context.properties.ConfigurationProperties class *<br>-keep @org.springframework.boot.autoconfigure.SpringBootApplication class *<br>-keep @org.springframework.stereotype.Repository class *<br>-allowaccessmodification<br>-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod,RuntimeVisibleAnnotations<br>-keepdirectories org.springframework.boot.autoconfigure<br>-keepclassmembernames class * {<br>     java.lang.Class class$(java.lang.String);<br>     java.lang.Class class$(java.lang.String, boolean);<br>}<br>-keep class * implements java.io.Serializable<br>-keepclassmembers enum * { *; }<br><br>######<br>-keeppackagenames com.bookportal.api.controllers<br>-keepnames class com.bookportal.api.controllers<br><br>-keepclassmembernames class com.bookportal.api.auth.** { *; }<br>-keepclassmembernames class com.bookportal.api.configs.WebFluxSecurityConfig { *; } # spring security<br>-keepclassmembernames @interface * { *; }<br>-keepclassmembernames class com.bookportal.api.repository.** { *; }<br>-keepclassmembernames class com.bookportal.api.entity.** { *; }<br>-keepclassmembernames class com.bookportal.api.model.** { *; }<br><br>-keep class com.bookportal.api.response.CustomResponse { *; }<br>-keep class com.bookportal.model.** { *; } #DTO<br>-keep class com.bookportal.repository.** { *; } #Spring Data <br>-keep class com.bookportal.entity.** { *; } #Database entities<br><br>-repackageclasses com.bookportal.api.proguard #move obfuscated class to<br>-classobfuscationdictionary proguard.txt #use these names while renaming classes<br>-obfuscationdictionary proguard.txt #use these names while renaming variables, methods etc.</pre><p>To tailor the build configuration for your application, update the MainClass and proguard.cfg sections in the pom.xml as appropriate for your setup. Additionally, consider adding a custom build configuration under a new Maven profile. This way, the build process will only be activated when that profile is specified, preserving the integrity of your base project structure.</p><p>Once these modifications are in place, execute mvn clean package to build the application. Afterward, inspect the generated JAR file to confirm the changes and ensure everything is working as expected.</p><p>UserService before:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1001/1*IOXrs0bKeuIf_VLGeGcFKw.jpeg" /></figure><p>UserService after:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l_n0L0J1vlkRxrduqXr_kA.jpeg" /></figure><p>Package Structure before-after:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*cZMsVVwzgYUbJ8d6qX1IaQ.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f34bb871776" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>