Making layout required for ivy repositories

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Making layout required for ivy repositories

chengas123
Hi,

I wanted to suggest making "layout" required when defining an Ivy repository for Gradle 3.0. The layout is the directory structure used to store artifacts. Ivy has a convention of using a certain directory structure layout and this layout can be specified by setting the layout to "ivy". Gradle by default uses its own non-standard directory layout structure. There's really no reason for this as far as I know except for legacy.

The problem with the non-standard directory structure is that it's very unexpected and hurts interoperability. I would always expect the conventional directory layout to be used instead of a custom layout since this is what I've been trained to expect from other tools. The reason I discovered this issue is that I was trying to publish a library with Gradle for use in an SBT project. It took me nearly an entire day to make this work because of a few different issues, but this was one of the largest. It would have saved a tremendous amount time to know that Gradle had chosen it's own behavior instead of using the convention defined by Ivy and used by other tools that read Ivy repos such as Ant, Eclipse, and SBT. If this were being written from scratch I think we can probably all agree it makes sense to use the standard layout since using a custom layout has several drawbacks and no benefits. The reason I like Gradle over other build tools is that it's easier to use and defaults are a big part of ease-of-use. I'd love to save others from the hours of frustration I experienced debugging a bad default.

Thanks,
Ben
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Making layout required for ivy repositories

Daz DeBoer-2
On Thu, Dec 11, 2014 at 12:18 PM, chengas123 <[hidden email]> wrote:
Hi,

I wanted to suggest making "layout" required when defining an Ivy repository
for Gradle 3.0. The layout is the directory structure used to store
artifacts. Ivy has a convention of using a certain directory structure
layout and this layout can be specified by setting the layout to "ivy".
Gradle by default uses its own non-standard directory layout structure.
There's really no reason for this as far as I know except for legacy.

The problem with the non-standard directory structure is that it's very
unexpected and hurts interoperability. I would always expect the
conventional directory layout to be used instead of a custom layout since
this is what I've been trained to expect from other tools. The reason I
discovered this issue is that I was trying to publish a library with Gradle
for use in an SBT project. It took me nearly an entire day to make this work
because of a few different issues, but this was one of the largest. It would
have saved a tremendous amount time to know that Gradle had chosen it's own
behavior instead of using the convention defined by Ivy and used by other
tools that read Ivy repos such as Ant, Eclipse, and SBT. If this were being
written from scratch I think we can probably all agree it makes sense to use
the standard layout since using a custom layout has several drawbacks and no
benefits. The reason I like Gradle over other build tools is that it's
easier to use and defaults are a big part of ease-of-use. I'd love to save
others from the hours of frustration I experienced debugging a bad default.


I'm not in favour of this change. I think Gradle has been around for long enough now that any change from the current default layout will:
a) Cause pain to existing users when they have to change their build scripts
b) Not solve the problem, because Gradle will no longer work out of the box with all of the existing Gradle-layout repositories out there.

I'd much rather solve this with better error messages and reporting. We already do a reasonable job of this when resolution fails:

* What went wrong:
Could not resolve all dependencies for configuration ':compile'.
> Could not find org.gradle.sample:quickstart:1.1.
  Searched in the following locations:
      file:/Users/daz/repo/org.gradle.sample/quickstart/1.1/ivy-1.1.xml
      file:/Users/daz/repo/org.gradle.sample/quickstart/1.1/quickstart-1.1.jar

But we could make better suggestions, possibly by exploring the repository to see if we can determine the layout. (i.e. We could check Ivy default locations and if 'ivy.xml' is found, suggest to the user that they use `layout "ivy"`)

It would also be good to add similar reporting to the dependencies report, because the above error doesn't aid in diagnosis if you are using a dynamic version (1.+), and you're picking up an older version from JCentre instead of a newer version from your repository (which is declared first).  
If the dependencies report could show something like this, it might help:
   \--- org.gradle.sample:quickstart:1.+ -> 1.1
      Searched in the following locations:
          file:/Users/daz/repo/org.gradle.sample/quickstart/* []
          file:/some/other/repo/org.gradle.sample/quickstart/* [0.9, 1.0]

This sort of extra reporting might be best in the HTML dependencies report, or maybe the dependencyInsight report.
--
Darrell (Daz) DeBoer
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Making layout required for ivy repositories

chengas123
I can certainly understand your first point that making layout required could increase the burden of upgrading. I'm not sure I understand why you say forcing the developer to set the layout would cause Gradle to no longer work out of the box with existing Gradle-layout repositories. That would only be true if they set the layout to something other than "gradle". The point is that by forcing them to set it they are cognizant of the fact that they are using the non-standard layout which is completely non-obvious today. What would also help with this is some mention in the documentation. I just sent a PR to update the docs: https://github.com/gradle/gradle/pull/367

It's an interesting idea to add error messages and reporting, which could be helpful if you're trying to read from a repository, but I think that generally works pretty well today. The case where it wouldn't help unfortunately is with what I think is the worse problem of publishing to a repository in non-standard format. Maybe we could require the layout be set only when publishing? I'm not sure if that's possible, but it seems like it would lessen the burden of forcing developers to update their build scripts and solve most of the problem I'm worried about.

Another idea would be to force the layout only when the repository url is "${System.properties['user.home']}/.ivy2/local". You really probably don't want to be writing to the default ivy repository in a non-default format.

-Ben
Loading...