Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4612272
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:22:49+00:00 2026-05-22T01:22:49+00:00

Is there way to use the jdepend plugin in maven to fail a build

  • 0

Is there way to use the jdepend plugin in maven to fail a build when package cycles exist? I know you can do it fairly easily with ant, but I haven’t figured out how to do it with maven.

thanks,
Jeff

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:22:50+00:00Added an answer on May 22, 2026 at 1:22 am

    You could write your own rule for the maven-enforcer plugin as described in

    http://maven.apache.org/enforcer/enforcer-api/writing-a-custom-rule.html

    That’s how I did it.

    NoPackageCyclesRule.java

    package org.apache.maven.enforcer.rule;
    
    import java.io.File;
    import java.io.IOException;
    
    import jdepend.framework.JDepend;
    
    import org.apache.maven.enforcer.rule.api.EnforcerRule;
    import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
    import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
    import org.apache.maven.plugin.logging.Log;
    import org.apache.maven.project.MavenProject;
    import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
    
    public class NoPackageCyclesRule implements EnforcerRule
    {
    
        public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException
        {
            Log log = helper.getLog();
    
            try
            {
                MavenProject project = (MavenProject) helper.evaluate("${project}");
                File targetDir = new File((String) helper.evaluate("${project.build.directory}"));
                File classesDir = new File(targetDir, "classes");
    
                if (project.getPackaging().equalsIgnoreCase("jar") && classesDir.exists())
                {
                    JDepend jdepend = new JDepend();
                    jdepend.addDirectory(classesDir.getAbsolutePath());
                    jdepend.analyze();
    
                    if (jdepend.containsCycles())
                    {
                        throw new EnforcerRuleException("There are package cycles");
                    }
                }
                else
                {
                    log.warn("Skipping jdepend analysis as " + classesDir + " does not exist.");
                }
            }
            catch (ExpressionEvaluationException e)
            {
                throw new EnforcerRuleException("Unable to lookup an expression "
                        + e.getLocalizedMessage(), e);
            }
            catch (IOException e)
            {
                throw new EnforcerRuleException("Unable to access target directory "
                        + e.getLocalizedMessage(), e);
            }
        }
    
        public String getCacheId()
        {
            return "";
        }
    
        public boolean isCacheable()
        {
            return false;
        }
    
        public boolean isResultValid(EnforcerRule arg0)
        {
            return false;
        }
    }
    

    pom.xml for enforcer rule:

    <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/maven-v4_0_0.xsd">
      <modelVersion>4.0.0</modelVersion>
    
      <groupId>custom-rule</groupId>
      <artifactId>no-package-cycles-rule</artifactId>
      <version>1.0</version>
    
      <properties>
        <api.version>1.0</api.version>
        <maven.version>2.2.1</maven.version>
      </properties>
    
      <dependencies>
        <dependency>
          <groupId>org.apache.maven.enforcer</groupId>
          <artifactId>enforcer-api</artifactId>
          <version>${api.version}</version>
        </dependency>
        <dependency>
          <groupId>org.apache.maven</groupId>
          <artifactId>maven-project</artifactId>
          <version>${maven.version}</version>
        </dependency>
        <dependency>
          <groupId>org.apache.maven</groupId>
          <artifactId>maven-core</artifactId>
          <version>${maven.version}</version>
        </dependency>
        <dependency>
          <groupId>org.apache.maven</groupId>
          <artifactId>maven-artifact</artifactId>
          <version>${maven.version}</version>
        </dependency>
        <dependency>
          <groupId>org.apache.maven</groupId>
          <artifactId>maven-plugin-api</artifactId>
          <version>${maven.version}</version>
        </dependency>
        <dependency>
          <groupId>org.codehaus.plexus</groupId>
          <artifactId>plexus-container-default</artifactId>
          <version>1.5.5</version>
        </dependency>
        <dependency>
          <groupId>jdepend</groupId>
          <artifactId>jdepend</artifactId>
          <version>2.9.1</version>
        </dependency>
      </dependencies>
    
    </project>
    

    Then you can add it to your build:

      <plugin>
        <artifactId>maven-enforcer-plugin</artifactId>
        <dependencies>
          <dependency>
            <groupId>custom-rule</groupId>
            <artifactId>no-package-cycles-rule</artifactId>
            <version>1.0</version>
          </dependency>
        </dependencies>
        <executions>
          <execution>
            <id>enforce-no-package-cycles</id>
            <goals>
              <goal>enforce</goal>
            </goals>
            <phase>verify</phase> <!-- use a phase after compile! -->
            <configuration>
              <rules>
                <NoPackageCyclesRule
                  implementation="org.apache.maven.enforcer.rule.NoPackageCyclesRule" />
              </rules>
            </configuration>
          </execution>
        </executions>
      </plugin>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to use C# to build a container application where each
is there a way to use Python paramiko package in order to scp or
Is there a way to use a SQLite query to get a list of
is there a way to use categories and ordered tests in MSTest together? [TestMethod,
Is there any way to use inheritance in database (Specifically in SQL Server 2005)?
Is there a way to use JQuery to cloak or encrypt email addresses on
Is there any way to use a constant as a hash key? For example:
Is there a way to use constants in JavaScript ? If not, what's the
Is there a way to use form fields that does not correspond to database
Is there a way to use .NET reflection to capture the values of all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.