You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于现有Tycho构建生成ProGuard混淆Feature的技术咨询

Got it, let's work through modifying your existing Tycho pipeline to produce ProGuard-obfuscated Features. I'll break this down into actionable steps with config examples and key pitfalls to watch out for.


1. Adjust Bundle-Level ProGuard Configuration

First, you need to ensure each bundle's ProGuard-obfuscated JAR replaces the default bundle JAR (so Features will pick up the obfuscated version automatically). Keep your existing tycho-source-plugin config (to generate source JARs) and add/tweak the proguard-maven-plugin setup:

<build>
  <plugins>
    <!-- Keep existing source JAR generation -->
    <plugin>
      <groupId>org.eclipse.tycho</groupId>
      <artifactId>tycho-source-plugin</artifactId>
      <version>${tycho.version}</version>
      <executions>
        <execution>
          <id>attach-sources</id>
          <goals>
            <goal>plugin-source</goal>
          </goals>
        </execution>
      </executions>
    </plugin>

    <!-- Configure ProGuard to replace the default bundle JAR -->
    <plugin>
      <groupId>com.github.wvengen</groupId>
      <artifactId>proguard-maven-plugin</artifactId>
      <version>${proguard.version}</version>
      <executions>
        <execution>
          <phase>package</phase>
          <goals>
            <goal>proguard</goal>
          </goals>
        </execution>
      </executions>
      <configuration>
        <injar>${project.build.finalName}.jar</injar>
        <outjar>${project.build.finalName}.jar</outjar> <!-- Overwrite default JAR -->
        <obfuscate>true</obfuscate>
        <keepdirectories>true</keepdirectories>

        <!-- Critical: Preserve OSGI metadata and required runtime elements -->
        <options>
          <option>-keepattributes Signature,InnerClasses,SourceFile,LineNumberTable</option>
          <option>-keep class org.osgi.framework.** { *; }</option>
          <option>-keep class * implements org.osgi.service.component.annotations.Component { *; }</option>
          <!-- Keep your bundle activator (if used) -->
          <option>-keep class com.yourcompany.yourapp.Activator { public *; }</option>
          <!-- Keep public API classes/methods if your bundle exposes an API -->
          <option>-keep class com.yourcompany.yourapp.api.** { public *; }</option>
          <!-- Add rules for reflection-heavy code (if applicable) -->
        </options>

        <!-- Include required dependencies for ProGuard analysis -->
        <libs>
          <lib>${java.home}/lib/rt.jar</lib>
          <lib>${java.home}/lib/jce.jar</lib>
          <lib>${tycho.osgi.bundle}/org.eclipse.osgi_*.jar</lib>
        </libs>

        <attach>false</attach> <!-- Don't attach as a secondary artifact -->
      </configuration>
    </plugin>
  </plugins>
</build>

Key Note: If you need to keep the unobfuscated JAR as an optional artifact, change the outjar to something like ${project.build.finalName}-obfuscated.jar and add <attach>true</attach>—but you'll need to update your Feature to explicitly reference this obfuscated JAR instead of the default one.


2. Update Feature Builds (Including Source Features)

Your existing Feature and Source Feature setup mostly stays the same—Tycho will automatically pull in the obfuscated bundle JARs as long as the bundle versions match what's declared in your feature.xml.

Keep your tycho-source-feature-plugin config to generate source features (these will still link to the original unobfuscated source JARs, which is correct for debugging):

<build>
  <plugins>
    <plugin>
      <groupId>org.eclipse.tycho.extras</groupId>
      <artifactId>tycho-source-feature-plugin</artifactId>
      <version>${tycho-extras.version}</version>
      <executions>
        <execution>
          <id>generate-source-feature</id>
          <goals>
            <goal>source-feature</goal>
          </goals>
        </execution>
      </executions>
      <configuration>
        <excludes>
          <!-- Exclude any bundles you don't want to include source for -->
        </excludes>
      </configuration>
    </plugin>
  </plugins>
</build>

3. Adjust P2 Repository & Category Configuration

No changes are needed to your category.xml—just keep referencing your regular Feature and Source Feature as before. When Tycho builds the P2 repository, it will package the Feature with its obfuscated bundle dependencies automatically.

Double-check your parent POM's module order to ensure builds run in the correct sequence:

  1. All Bundles (with ProGuard processing)
  2. All Features (including source features)
  3. Category/P2 Repository
  4. Product

4. Validate Product Build/Instantiation

If your product is Feature-based, it will automatically use the obfuscated bundles once you reference the updated Feature in your product definition. However, watch out for:

  • Reflection Issues: If your code uses reflection, ProGuard may have obfuscated class/method names. Add specific -keep rules for these cases.
  • Runtime Errors: Test the product thoroughly—look for ClassNotFoundException or NoSuchMethodError in logs, which indicate missing ProGuard keep rules.
  • Debugging: If you need to debug obfuscated code, add -printmapping mapping.txt to your ProGuard options. You can load this mapping file in your debugger to map obfuscated names back to original code.

5. Parent POM Version Management

To keep plugin versions consistent across your modules, define them in your parent POM:

<properties>
  <tycho.version>4.0.0</tycho.version>
  <tycho-extras.version>4.0.0</tycho-extras.version>
  <proguard.version>6.2.2</proguard.version>
</properties>

<build>
  <pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.eclipse.tycho</groupId>
        <artifactId>tycho-maven-plugin</artifactId>
        <version>${tycho.version}</version>
        <extensions>true</extensions>
      </plugin>
      <!-- Add other plugin version definitions here -->
    </plugins>
  </pluginManagement>
</build>

内容的提问来源于stack exchange,提问作者pitseeker

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 09:19:44