There's another option, and that's to unpack the source archive and recompile during the build:
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.1.2</version>
                <executions>
                    <execution>
                        <id>get-commons-fileupload-sources</id>
                        <phase>process-sources</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>commons-fileupload</groupId>
                                    <artifactId>commons-fileupload</artifactId>
                                    <classifier>sources</classifier>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>${project.build.directory}/fileupload-source</outputDirectory>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>commons-io</groupId>
                                    <artifactId>commons-io</artifactId>
                                    <version>2.8.0</version>
                                    <classifier>sources</classifier>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>${project.build.directory}/fileupload-source</outputDirectory>
                                </artifactItem>
                            </artifactItems>
                            <excludes>org/apache/commons/fileupload/portlet/*</excludes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <id>add-commons-fileupload-sources</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${project.build.directory}/fileupload-source</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.google.code.maven-replacer-plugin</groupId>
                <artifactId>replacer</artifactId>
                <version>1.5.3</version>
                <executions>
                    <execution>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>replace</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <includes>
                        <include>${project.build.directory}/fileupload-source/**/*.java</include>
                    </includes>
                    <replacements>
                        <replacement>
                            <token>javax.servlet</token>
                            <value>jakarta.servlet</value>
                        </replacement>
                    </replacements>
                </configuration>
            </plugin>