Disable Cockpit/Tasklist plugin in Spring-Boot webapp

TL;DR;

As a hacky solution, you can replace Camunda’s webjar with your own version.

This solution is based on Spring Boot: Replace config.js for Webapps-Configuration, eUmzugPrototyp and some trial and error from my side.

Details

The docs say “You can exclude some plugins from the interface by adding a cam-exclude-plugins attribute to the HTML base tag of the page loading the interface.” The problem is that the page loading the interface is part of a referenced library. So you will need to manipulate this library.

The main steps are:

  1. Create a separate Maven project
    a. unpack the original webjar
    b. add a custom index index.html with the desired plugin exclusions
  2. In your main Spring Boot application
    a. exclude Camunda’s webjar
    b. reference your newly generated webjar

Ho to achieve this?

Create a Maven project containing just an index.html. You can copy the index.html from a Camunda distro and manipulate the HTML base tag according to your needs. For example, in the Tomcat distro, the path is camunda-bpm-tomcat-7.15.0\server\apache-tomcat-9.0.43\webapps\camunda\app\cockpit\index.html. This index.html also contains sample code how to exlude a plugin.

In the POM of this project, use Maven plugins to unpack Camundas webjar and to copy our custom index.html to an appropriate location. An example POM (based on Björns POM) is here:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    
    <!-- Same version as in your main project -->
    <parent>
        <groupId>org.camunda.bpm</groupId>
        <artifactId>camunda-parent</artifactId>
        <version>7.15.0</version>
    </parent>
    
    <groupId>ch.zhaw.gpi</groupId>
    <artifactId>be-services-webapp-webjar</artifactId>
    <name>BEservices Plattform</name>
    <packaging>jar</packaging>
    
    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        
        <camunda.version>7.15.0</camunda.version>      
        
        <skipTests>true</skipTests>
    </properties>

    <dependencies>
        <!-- Von den Webapps benötigen wir die das mit classes benannte Subset an Dateien -->
        <dependency>
            <groupId>org.camunda.bpm.webapp</groupId>
            <artifactId>camunda-webapp</artifactId>
            <type>jar</type>
            <classifier>classes</classifier>
        </dependency>

        <!-- Und schliesslich benötigen wir das WebJAR, wobei dieses als optional gekennzeichnet wird, weil die aufrufenden Projekte dadurch wissen, dass sie es nicht zwingend als Abhängigkeit benötigen. Warum? Weil wir es ja anschliessend selbst in Form dieses Projekts ausgeben -->
        <dependency>
            <groupId>org.camunda.bpm.webapp</groupId>
            <artifactId>camunda-webapp-webjar</artifactId>
            <type>jar</type>
            <optional>true</optional>
        </dependency>
    </dependencies>

    <build>
        <finalName>${project.artifactId}</finalName>
        
        <plugins>
            <!-- Unpack the original webjar -->
            <plugin>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack</id>
                        <phase>process-sources</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.camunda.bpm.webapp</groupId>
                                    <artifactId>camunda-webapp-webjar</artifactId>
                                    <version>${project.version}</version>
                                    <type>jar</type>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>${project.build.outputDirectory}</outputDirectory>
                                    <includes>**</includes>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

			
			<!-- Overwrite index.html with the content of our folder html (contains just our custom index.html) -->
			<plugin>
                <artifactId>maven-resources-plugin</artifactId>
				<executions>
					<execution>
						<id>replace-index</id>
						<phase>prepare-package</phase>
						<goals>
							<goal>copy-resources</goal>
						</goals>
						<configuration>
							<outputDirectory>${project.build.outputDirectory}/META-INF/resources/webjars/camunda/app/cockpit</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>html</directory>
                                    <filtering>false</filtering>
                                </resource>
                            </resources>
						</configuration>
					</execution>
				</executions>
			</plugin>
			
            <!-- Ohne die folgende Angaben versucht Maven mit JDK 5 zu kompilieren -->
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    
</project>

In your main project, make sure the original Camunda webjar is excluded

        <dependency>
            <groupId>org.camunda.bpm.springboot</groupId>
            <artifactId>camunda-bpm-spring-boot-starter-webapp</artifactId>
            <version>${camundaSpringBoot.version}</version>
            <exclusions>
            	<exclusion>
            		<groupId>org.camunda.bpm.webapp</groupId>
            		<artifactId>camunda-webapp-webjar</artifactId>
            	</exclusion>
            </exclusions>
        </dependency>

and your custom webjar is included

        <dependency>
        	<groupId>ch.zhaw.gpi</groupId>
        	<artifactId>be-services-webapp-webjar</artifactId>
        	<version>${camunda.version}</version>
        </dependency>
3 Likes