Thank you for replying Elliotte,
I hired someone on Fiverr to try to figure out a workaround for this. He
was not successful however he may have been close.  He added <
*classpathDependencyExcludes*> to the build path in the pom.xml. Can you
take a look at the attached pom and see if there's anything I can do to
make this work? He was using gson in this example.

Scott



On Fri, Jan 24, 2020 at 5:02 AM Elliotte Rusty Harold <[email protected]>
wrote:

> That's a really interesting idea and I can see the use of it. I'm not
> sure it fits with how scopes work in Maven or classpaths in Java
> though. A scope generally defines which jars are and are not added to
> the classpaths of which goals/plugins/stages, not which parts of the
> source tree can see what. Perhaps this would work if your proposed
> main scope were added to compile and run but not test? However, I
> suspect the transitive dependencies would still be needed in the
> classpath or the tests will fail with runtime NoClassDefFoundErrors
> and the like.
>
> What you want sounds a little like strict_java_deps in bazel:
> https://blog.bazel.build/2017/06/28/sjd-unused_deps.html
>
> On Thu, Jan 23, 2020 at 2:17 AM Scott Wilson <[email protected]> wrote:
> >
> > *Hi Robert and devs*
> >
> >
> > *I have been using maven for a few years and I LOVE it!*
> >
> >
> > *I have a feature request.*
> >
> >
> > *(1) When adding a dependency to pom.xml the default scope is everywhere*
> >
> > *ie src/main/java/....*
> >
> > *and src/tst/java/...*
> >
> >
> > *(2) When adding <test> as the scope then the dependency can ONLY be used
> > under src/tst/java...*
> >
> > *If referencing the dependency in src/main/java/... then it will not
> > compile*
> >
> >
> > *(3) My feature request:*
> >
> > *I want the exact opposite. I'd like a new scope called <main>*
> >
> > *If the scope is <main> then the dependency can ONLY be used under
> > src/main/java/...*
> >
> > *If referencing the dependency in tst/main/java/.... then it will not
> > compile*
> >
> >
> > *I read up on scopes
> > (**
> https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope
> > <
> https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope
> >)
> > *and
> > AFAIK this is not currently supported, but I have a specific reason for
> > wanting this.
> >
> >
> > *I'd really appreciate if someone can add that for me and let me know
> when
> > it's done.*
> >
> > *Please let me know if you have any questions.*
> >
> >
> > *Regards*
> >
> > *Scott Wilson*
> >
> > *http://linkedin.com/in/hockeyeh <http://linkedin.com/in/hockeyeh>*
>
>
>
> --
> Elliotte Rusty Harold
> [email protected]
>
<?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>

    <groupId>wait-demo</groupId>
    <artifactId>wait-demo</artifactId>
    <version>1.0</version>

    <properties>
        <java-version>1.7</java-version>
        <projectEncoding>utf-8</projectEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.3</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <!-- Compiler -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>${java-version}</source>
                    <target>${java-version}</target>
                    <encoding>utf-8</encoding>
                    <showWarnings>true</showWarnings>
                </configuration>
            </plugin>

            <!-- Tests -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.17</version>
                <configuration>
                    <junitArtifactName>junit:junit</junitArtifactName>
                    <includes>
                        <include>**/*Test.java</include>
                    </includes>
                    <excludes>
                        <exclude>**/*AbstractTest.java</exclude>
                    </excludes>

                    <classpathDependencyExcludes>
                        <classpathDependencyExclude>com.google.code.gson:gson</classpathDependencyExclude>
                    </classpathDependencyExcludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to